c# - 在 C# 中编辑字符串中的字符

标签 c# .net c++ string

在 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/

相关文章:

c++ - 是否有用于 C(C99 或其他)的标准化和常用库,因为 STL 用于 C++?

c# - Html.ValidationMessageFor 文本颜色

c# Regex 前瞻失败

c# - 限制可以使用打开文件对话框选择的文件

c++ - QSerialPort 单独读取十六进制值

c++ - 为什么在 C 程序中从 main() 返回 0?

c# - rijndael 加密 - 只有部分字符串被解密

同一文件中的 C# 接口(interface)和实现 - 好主意吗?

.net - 判断是在 .NET 中的生产环境还是开发环境中的最佳方法

c# - 使用 Thrift 从 .NET 连接到 Cassandra