且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过索引快速替换字符串中的多个字符

更新时间:2023-02-12 18:57:30

,除了

in base R, besides the method of substring() and for-loop shown by @akrun,, you can use utf8ToInt() and intToUtf8 to make it

v <- utf8ToInt(string)
v[string_indexes_replaced ] <- utf8ToInt("*")
res <- intToUtf8(v)

给出

> res
[1] "*bc*e*gh*j"