none
How to write new line character \n in resx file? RRS feed

  • Question

  •  How to write new line character \n in resx file (e.g MyFile.resx)?

    Example: I have resx file with property MyMessage = "One line\nNextLine"

    When I used:

    MessageBox.Show(MyFile.MyMessage) I had message in one line (without Enter).

    When I used:

    MessageBox.Show("One line\nNextLine") I had message with two lines.

    Tuesday, January 6, 2009 1:54 PM

Answers

  • You can also use Shift + Enter in the resource editor...

    • Marked as answer by kicaj Monday, July 19, 2010 7:03 PM
    Monday, May 10, 2010 10:50 PM
  • View code on the .resx file, and add carriage returns in the .resx file.  Your value should look like this (the line break after the first Test is intentional, and creates a carriage return in the resulting string value).

      <data name="Test" xml:space="preserve">

        <value>Test

    Test</value>

      </data>


    David Morton - http://blog.davemorton.net/
    • Marked as answer by kicaj Tuesday, January 6, 2009 8:39 PM
    Tuesday, January 6, 2009 3:19 PM
    Moderator

All replies

  • View code on the .resx file, and add carriage returns in the .resx file.  Your value should look like this (the line break after the first Test is intentional, and creates a carriage return in the resulting string value).

      <data name="Test" xml:space="preserve">

        <value>Test

    Test</value>

      </data>


    David Morton - http://blog.davemorton.net/
    • Marked as answer by kicaj Tuesday, January 6, 2009 8:39 PM
    Tuesday, January 6, 2009 3:19 PM
    Moderator
  • MessageBox.Show(MyFile.MyMessage.Replace("\\n","\n")); 

    Will work.
    Tuesday, January 6, 2009 4:35 PM
  • Another solution for \n would be:

    resx file with property MyMessage = "One line &#13; NextLine"

    (omit the whitespace for proper formatting)

     

    You can add tab ( \t ) in the same manner:  &#9;

     

    Thanx, good ol' ASCII codes :)

     

    Martin
    Wednesday, April 21, 2010 8:46 AM
  • You can also use Shift + Enter in the resource editor...

    • Marked as answer by kicaj Monday, July 19, 2010 7:03 PM
    Monday, May 10, 2010 10:50 PM
  • LOL!!
    Monday, April 2, 2012 10:08 AM