C# 中 string 的 Replace 需要返回值

作者:vkvi 来源:ITPOW(原创) 日期:2007-6-27

C# 中 string 对象的 Replace 语法是:

string string.Replace(string oldValue, string newValue)

我们可能常常忘了应用其返回值,比如:要将 str 中的 "1" 替换成 "2",下面的做法是不正确的:

str.Replace("1", "2");

正确的做法是:

str = str.Replace("1", "2");

相关文章