如何将\n/g替换为<;br/>;在c#中?
在jQuery中,以下代码起作用如何将\n/g替换为<;br/>;在c#中?,c#,model-view-controller,C#,Model View Controller,在jQuery中,以下代码起作用 item[j].Comments.replace(/\n/g, "<br />") 项[j]。注释。替换(/\n/g,“”) 现在我想在控制器或视图中用换行符替换注释空格,但不会得到jQuery显示的相同结果 给定: string s = "Some text with newlines ...."; 这将是: s= s.Replace( Environment.NewLine, "<br/>" ); s=s.Replace(En
item[j].Comments.replace(/\n/g, "<br />")
项[j]。注释。替换(/\n/g,“
”)
现在我想在控制器或视图中用换行符替换注释空格,但不会得到jQuery显示的相同结果 给定:
string s = "Some text with newlines ....";
这将是:
s= s.Replace( Environment.NewLine, "<br/>" );
s=s.Replace(Environment.NewLine,
);
或(不使用环境)
s=s.Replace(“\r\n”和“
”)//窗户
s=s。替换(“\r”和“
”)//苹果
s=s。替换(“\n”和“
”)//linux
因此,在你的情况下:
item[j].Comments = item[j].Comments.Replace( Environment.NewLine, "<br/>" );
item[j]。Comments=item[j]。Comments.Replace(Environment.NewLine,“
”);
多了解一些细节就好了。这段代码(用C语言)编译吗?您正在使用哪些库/框架?您是否有一个现有的控制器和视图?如果您有一个C#中的字符串,并且希望将所有的“\n”替换为“”,那么您可以使用
myString=myString.replace(“\n”,“
”)代码>是的代码在C#中编译,我使用的是mvc5。是的,我有控制器和视图。错误推理:我在视图中使用您的代码,但它不工作。您需要显示更大的代码片段,以便我为您提供更有用的东西。
item[j].Comments = item[j].Comments.Replace( Environment.NewLine, "<br/>" );