首页 > c# 中如何替换换行符

c# 中如何替换换行符

c#中如何替换换行符
string strpageContent = strpageContent.Replace("\r\n", "");
这种方式好像无法正确替换


替换固定字符没必要用正则表达式,效率差。


string str = "line1 \r\n line2 \n line3 \r"; str = str.Replace(System.Environment.NewLine, ""); //OK str = str.Replace("\r", "").Replace("\n", ""); //也OK

string pattern = @"\r*\n";
Regex rgx = new Regex(pattern);

string outputStr = rgx.Replace(strpageContent, "");

【热门文章】
【热门文章】