C#字符串中的换行符 [英] newline character in c# string

查看:213
本文介绍了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 />");

这篇关于C#字符串中的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆