locked
Environment.NewLine RRS feed

  • Question

  • User895691971 posted

    Hi, 

    I read a post somewhere saying that to save the TextArea line breaks we need to write this code

    txtArea.Text = input.Replace(Environment.NewLine, "<br />");

    But where? Before saving? Or after saving and before viewing?

    Saturday, July 13, 2013 9:56 AM

Answers

  • User1648350404 posted

    What it looks...

    In the database textarea text is saved with \n ...etc.

    Now you have to display on page after replacing line breaks to <br/>

    It should be label to display in readonly mode

    lblArea.Text = input.Replace(Environment.NewLine, "<br />");



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 13, 2013 10:04 AM
  • User-1716253493 posted
    You can do this when you want to save it to database or direct viewing for example using label. When viewing from database, you don't need to do that anymore.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 13, 2013 10:40 AM
  • User1648350404 posted

    Exactly

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 13, 2013 12:09 PM

All replies

  • User1648350404 posted

    What it looks...

    In the database textarea text is saved with \n ...etc.

    Now you have to display on page after replacing line breaks to <br/>

    It should be label to display in readonly mode

    lblArea.Text = input.Replace(Environment.NewLine, "<br />");



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 13, 2013 10:04 AM
  • User895691971 posted

    Ok, so you mean I need to extract the data as variable and then replace '\n' with <br>?

    Saturday, July 13, 2013 10:31 AM
  • User-1716253493 posted
    You can do this when you want to save it to database or direct viewing for example using label. When viewing from database, you don't need to do that anymore.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 13, 2013 10:40 AM
  • User895691971 posted

    Ok, one answer please!

    If the text saved in Database contains <br> and when i write it in some div, will that <br> transform into a <br> or it will still be a text <br>?

    Saturday, July 13, 2013 10:42 AM
  • User-1716253493 posted
    It should line break in browser.
    Saturday, July 13, 2013 11:06 AM
  • User895691971 posted

    You mean by writing this in textarea 

    "Hi my name is Afzaal.

    i am 17 years old."

    Will be "Hi my name is Afzaal.\n i am 17 years old." Then to save it if I do that replace, I will get the value as: "Hi my name is Afzaal.<br /> i am 17 years old." And when being executed at browser it will be again as" 

    "Hi my name is Afzaal.

    i am 17 years old."

    Right?

    Saturday, July 13, 2013 12:07 PM
  • User1648350404 posted

    Exactly

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 13, 2013 12:09 PM