string.Replace() 不更新字符串 [英] string.Replace() doesn't update the string
本文介绍了string.Replace() 不更新字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用 string.Replace() 函数,但效果不佳.
I tried use the string.Replace() function, but it doesn't work right.
string test = "AAA AA AA faseffs AEfAfse AFAEf AEFAEf";
test.Replace('A', 'C');
label.Text = test;
label
向我显示 test
字符串而不替换任何内容.
label
shows me the test
string without replacing anything.
推荐答案
字符串在 NET 中是不可变的.Replace 使用替换的字符构建一个新字符串并返回它.您可以将返回的字符串分配给用于调用 Replace 方法的同一字符串(或分配给新的字符串变量)
Strings are immutable in NET. Replace works building a new string with the replaced chars and returning it. You could assign the returned string to the same string used to call the Replace method (or to a new string variable)
test = test.Replace('A', 'C');
这篇关于string.Replace() 不更新字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文