Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
它给我一个错误,不知道为什么。我想替换'为".
'
"
try { txtCS.Text.Replace("'", """); } catch { }
该Replace方法返回一个字符串,因为字符串本身是不可变的。这意味着它不会更改现有字符串 ( txtCS.Text),而是创建一个新字符串对象,因此您需要将该新字符串对象分配给文本框。
Replace
txtCS.Text
此外,您在引号中缺少转义字符。通过添加 a \,您可以使用该"字符,否则编译器会认为您正在关闭字符串。
\
txtCS.Text = txtCS.Text.Replace("'", "\"");