Remove \r from string
I have some Html in string I have tried utmos开发者_如何学运维t to remove \r many times but fails.
text.Replace("\r\n", "").Replace("\r", "").Replace("\n", "");
You need to assign the result back to text
, like:
text = text.Replace("\r\n", "").Replace("\r", "").Replace("\n", "");
You're close:
text = text.Replace("\r\n", "").Replace("\r", "").Replace("\n", "");
You have to assign the result of the .Replace operation back to the string itself (or another one). Otherwise the result goes nowhere.
text.Replace
returns the newly modified string. It does not change the string it is operating against. So make sure you are capturing the return value.
str = str.Replace("\\\\r","").Replace("\\\\n","");
you probably need to use an escape character
.Replace("\r", "").Replace("\n", "")
Didn't remove "\r\n" in my input. Then I remembered that \r and \n are special characters which needed to be escaped, hence the following worked for me:
.Replace(@"\r", "").Replace(@"\n", "")
精彩评论