2014-07-15 58 views
-2

我想弄清楚一个简单的方法从字符串中删除\ 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”

+0

的可能重复[我怎样才能把 “\ r \ n” 在C#中的字符串?我可以使用regEx吗?](http://stackoverflow.com/questions/1981947/how-can-i-remove-rn-from-a-string-in-c-can-i-use-a-regex) –

+0

使用'string.replace()' – Rahul

+1

你给'text.Replace()'调用某处的结果吗?它不会在原地替换它 – zerkms

回答

15

读取更好:

text = text.Replace(System.Environment.NewLine, string.Empty); 
2

你设定的返回值回变量?

text = text.Replace("\r\n", ""); 
2

它返回一个值。你需要说text = ...

text = text.Replace("\r\n", ""); 
1

你最好试试这个。

text = text.Replace("\r\n", ""); 

希望这项工作。

0

试试这个。

text = text .Replace("\\r\\n", ""); 

这对我的工作;)