在 C# 中编辑字符串中的字符最简洁的方法是什么?
C++ 中的 C# 等价物是什么:
std::string myString = "boom";
myString[0] = "d";
最佳答案
使用 StringBuilder
代替。
string is immutable as described by MSDN :
Strings are immutable--the contents of a string object cannot be changed after the object is created, although the syntax makes it appear as if you can do this.
所以你想要这样的东西:
StringBuilder sb = new StringBuilder("Bello World!");
sb[0] = 'H';
string str = sb.ToString();
关于c# - 在 C# 中编辑字符串中的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2931288/