我想弄清楚一个简单的方法从字符串中删除\ r \ n。如何从字符串中删除 r n c#
示例: 文本=
我试图 “this.is.a.string \ r \ nthis.is.a.string \ r \ n”:
text.Replace("\r\n", "")
和text.Replace("\r\n", string.Empty)
但它不没有工作。 \r\n
仍然在字符串中...
的结果应该是:“this.is.a.string.this.is.a.string”
我想弄清楚一个简单的方法从字符串中删除\ r \ n。如何从字符串中删除 r n c#
示例: 文本=
我试图 “this.is.a.string \ r \ nthis.is.a.string \ r \ n”:
text.Replace("\r\n", "")
和text.Replace("\r\n", string.Empty)
但它不没有工作。 \r\n
仍然在字符串中...
的结果应该是:“this.is.a.string.this.is.a.string”
读取更好:
text = text.Replace(System.Environment.NewLine, string.Empty);
你设定的返回值回变量?
text = text.Replace("\r\n", "");
它返回一个值。你需要说text = ...
text = text.Replace("\r\n", "");
你最好试试这个。
text = text.Replace("\r\n", "");
希望这项工作。
试试这个。
text = text .Replace("\\r\\n", "");
这对我的工作;)
的可能重复[我怎样才能把 “\ r \ n” 在C#中的字符串?我可以使用regEx吗?](http://stackoverflow.com/questions/1981947/how-can-i-remove-rn-from-a-string-in-c-can-i-use-a-regex) –
使用'string.replace()' – Rahul
你给'text.Replace()'调用某处的结果吗?它不会在原地替换它 – zerkms