locked
How to replace line breaks in mvc 5? RRS feed

  • Question

  • User-1672104984 posted

    How can I replace Line Breaks within a string in <g class="gr_ gr_138 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="138" data-gr-id="138">mvc</g>?

    Thursday, March 14, 2019 10:04 AM

All replies

  • User753101303 posted

    Hi,

    A usual approach is to use MyString.Replace("\n","<br>");

    By default HTML is ignored line breaks (and consecutive whitespaces). If on particular elements you could also try to alter this default behavior using https://developer.mozilla.org/en-US/docs/Web/CSS/white-space and use your string unchanged.

    Edit : note that String.Replace returns a new string that you'll then consume. It's doesn't "update" the source string.

    Thursday, March 14, 2019 10:18 AM
  • User1520731567 posted

    Hi shaileshn011,

    How can I replace Line Breaks within a string in mvc?

    According to your requirement,I think you could use replace(),I make a simple demo,you could refer to:

            var str = "Test\r\nOne";
            console.log(str);   
            var myString = str.replace("\r\n", "aa");
            console.log(myString);

    Output:

    If you would like to remove line breaks,you could code like:

    str.replace("\r\n", "");

    Other solutions,you could refer to this link:

    https://stackoverflow.com/questions/238002/replace-line-breaks-in-a-string-c-sharp

    Best Regards.

    Yuki Tao

    Friday, March 15, 2019 3:08 AM