Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GJ100 opened this issue May 17, 2023 · 0 comments
Open

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

GJ100 opened this issue May 17, 2023 · 0 comments

Comments

@GJ100
Copy link

GJ100 commented May 17, 2023

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

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant