asp.net: line break \n in resource .resx file does not work

吃可爱长大的小学妹 提交于 2019-12-06 02:38:23

问题


The "\n" does not work in below code, it's just displayed as "\n"

if (!window.confirm(XXXXX.Globalization.LocalResource.InvalidUrl)) {
    return false;
}

the string is "Invalid URL! \n Are you sure you want to continue?" in resource resx file.

how to make it work?


回答1:


Try shift-enter to create a new line in the designer. Alternatively copy and paste the result from notepad.

Another way is to edit the RESX xml manually.

The problem is that the RESX designer UI will auto-escape the strings. So your value is actually:

"Invalid URL! \\n Are you sure you want to continue?"



回答2:


What worked in my case was this:

This text has a<br>line break!

See the <br> there.

Look here for the details: Putting a line break in an resx resource file

I'm using Razor in ASP.NET MVC and so I used:

@Html.Raw(Localization.NotAnswered)

so that it outputs the <br> as HTML code.




回答3:


Use break tag "<br/>" instead of "\n"

EDITED

This should surely work

use "\r\n"



回答4:


I used shift+enter, it think it's the simplest.

< br >certainly will not work, have not tried \r\n, but since \n does not work, I am not very confident with \r\n




回答5:


ASP.NET MVC

STEP-1
In my Resource.resx file put Shift+Enter between the paragraph1 & paragraph2
My text paragraph1
My text paragraph2

STEP-2
In my view page its

<p>@Html.Raw(Regex.Replace(Resource.Mytext, "\r\n", "<br />"))</p>



回答6:


Shift-enter works great when you're entering strings, but if you have already created your resource file, and you dont want to edit every string, you can just do

String myStringFromResx = myStringFromResx.Replace("\\n," "\n");


来源:https://stackoverflow.com/questions/10876242/asp-net-line-break-n-in-resource-resx-file-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!