string.replace不适用于引号

时间:2014-11-14 14:29:13

标签: c# string replace

我有一个像

这样的字符串
mukesh "salaria" engineer

我如何更换"空白

就像我希望输出为

mukesh salaria engineer

我已经尝试了,

 str.replace("\"",string.empty);
但它并不适合我。

4 个答案:

答案 0 :(得分:2)

它有效,但必须输入:str = str.replace(...)

答案 1 :(得分:1)

您必须使用Replace方法并从中获取字符串。您的代码必须是:

str = str.Replace("\"", string.Empty);

msdn :

  

返回一个新字符串,其中当前实例中所有出现的指定字符串都被另一个指定的字符串替换。

答案 2 :(得分:1)

string.Replace是一个纯方法(没有副作用)。如果你没有将str.replace("\"",string.empty);分配给任何东西,那么该语句不会对你的对象状态做任何改变(换句话说,写这行代码就等于根本不写它。)。

使用str = str.Replace(...);

答案 3 :(得分:-2)

试试这个

str.Replace('\"',' ');