C#字符串中的换行符
我在C#字符串中有一些html代码.如果我看一下Visual Studio的文本可视化器,可以看到其中包含许多换行符.但是,在我应用此代码之后
I have some html code in a C# string. If I look with the Text Visualizer of Visual Studio I can see it has numerous newlines in it. However, after i apply this code
string modifiedString = originalString.Replace(Environment.NewLine, "<br />");
,然后在ModifyString上使用Text Visualizer进行查看,我可以看到除了3个地方之外,它不再有换行符.除了换行符,还有其他字符类型吗?我想念吗?
and then I look with the Text Visualizer at modifiedString I can see it doesn't have anymore newlines except for 3 places. Are there any other character types than resemble newline and I am missing?
它们可能只是\r
或\n
.我刚刚检查了一下,VS 2010中的文本可视化工具既显示为换行符,也显示为\r\n
.
They might be just a \r
or a \n
. I just checked and the text visualizer in VS 2010 displays both as newlines as well as \r\n
.
此字符串
string test = "blah\r\nblah\rblah\nblah";
显示为
blah
blah
blah
blah
在文本可视化器中.
所以您可以尝试
string modifiedString = originalString
.Replace(Environment.NewLine, "<br />")
.Replace("\r", "<br />")
.Replace("\n", "<br />");