Carriage Return / Line Feed in .Net Resource File (App_GlobalResources)

I save several texts in the file App_GlobalResources.resx .

Texts must be multi-line, and I need them to contain line feeds. However, when I read the contents, all line feeds disappear ( \r\n is printed, and not as a CRLF 10 13 control character).

I know that I could get around this by replacing \r\n (or something else in this case) again with CRLF when I read the content, but I wondered why these explicitly resx text files ignore control characters - and CRLF is important - and if anyone knows if there is a setting or something that will allow it to work in a natural way.

+81
newline line-breaks resx resource-files
May 31 '09 at 2:25 a.m.
source share
5 answers

I used VB.NET Express Edition to test this.

In the resource editor (where you can specify the name of the resource and the contents of the string), put the contents of the string, separated by Shift + Enter .

Suppose you want to enter

 hello world 

Type hi, then Shift + Enter and Peace.

If you look at the Resources.Resx file (which is an XML file), you will see that it creates a node with the xml:space="preserve" attribute.

Second option

In addition, you can manually edit Resource.resx and change the contents located in the CDATA section.

Suppose you have a string named "example". Locate it in Resource.resx and modify the contents to have a CDATA section inside it against a simple value.

eg.

 <data name="example"> <![CDATA[ hello world 1 2 3 4 ]]> </data> 
+144
May 31 '09 at 6:49 a.m.
source share

Use Shift + Enter to insert a new line.

+29
Aug 18 '09 at 10:08
source share

When using resx constructor interface

  • If you actually enter text in a resx file, you should use

    Shift + Enter

    as indicated in other answers.

  • If you paste text in resx - Visual Studio will paste the text in the same format as it is already (including linebreaks / multiline).

When opening a resx file in XML format

(find the resx file using find and replace .. when you click on the file in the "find results" panel, VS will open the resx file in XML)

Here you can add text as you wish (in value tags), and the formatting will be saved.

+16
Aug 28 '12 at 11:24
source share

Well, that worked in my situation using the <br> tag, like this:

 A text with a line break <br> and this goes in the second line. 

There is a message with more information here: Enabling line break in resx resource file

If you use the Razor viewer with ASP.NET MVC, you need to use:

 @Html.Raw(ResourceFile.ResourceString) 

so that it prints <br> as HTML.

+11
Aug 01 '12 at 18:45
source share

You can edit *.resx with a text editor to add line breaks.

You can do this even in Visual Studio:

  • Right click resource file
  • Click to Open with...
  • Select XML (Text) Editor with Encoding
  • Click OK
  • Press OK once to select the encoding (auto detect)
  • Find the name (key) of your text (for example, "MY_TEXT")
  • Edit the text inside the <value> . To translate a line, just press Enter . Note. Remove the leading spaces after the line break. Otherwise, they are also inserted.

Tested with Visual Studio 2017.

Example:

  <data name="MY_TEXT" xml:space="preserve"> <value>Line 1 Line 2 Line 3</value> </data> 
0
Dec 17 '18 at 18:23
source share



All Articles