xe-utils icon indicating copy to clipboard operation
xe-utils copied to clipboard

添加一个指定位置替换字符的函数

Open GJ100 opened this issue 2 years ago • 0 comments

这个需求解决了什么问题:

JS自带的replace中只能替换所有符合的字符,但是我想有一个可以替换指定位置的字符,就是只修改指定位置的那一个。

建议的 API 是什么样的:

replaceInposition

是否已有其他不错的替代方案:

这个是用JS实现的简单案例: let myString = "hello"; let indexToReplace = 1; // 字符串中第二个字符,即索引值为 1 myString = myString.substring(0, indexToReplace) + "a" + myString.substring(indexToReplace + 1); console.log(myString); // 输出 "hallo"

GJ100 avatar May 17 '23 04:05 GJ100