CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2011

    Angry RichTextBox + MySQL String and '\n' problem...

    Hi there!

    My problem is simply I quess.

    I'm trying to retrieve string from the database using:

    rtbText.Text = reader.GetString('description');

    Ok, well in fact it is reading etc, but if I add \n new line char it just displays it as is...

    For example:

    In database I have smth like: "Polish:\nTen mod daje[..]\n\nEnglish:\nThis mod gives[...]" and it is showing exactly the same in rtb, i tried to replace it with:

    rtbText.Text.Replace("\n", Environment.NewLine);

    But it did nothing...

    I tried to replace it with MySQL like:

    UPDATE mods SET description = REPLACE(description, '\n', CHAR(10));

    However, it didn't work.

    I'm actually out of ideas... help someone?

  2. #2
    Join Date
    Jun 2011

    Re: RichTextBox + MySQL String and '\n' problem...


    rtbText.Text.Replace("\n", "\n\r");
    rtbText.Text.Replace("\n", "\r\n");

  3. #3
    Join Date
    Feb 2011
    United States

    Re: RichTextBox + MySQL String and '\n' problem...

    So you can literally see the \n's in the string? You can correct this with:

    rtbText.Text.Replace("\\n", Environment.NewLine);
    As you wrote it, you were replacing newline characters (the \ escapes the n so that \n means newline instead of literally \n. To avoid escaping you have to escape the slash by using \\ to tell it "I literally mean slash, and am not escaping another character."

    Good explanation: http://en.wikipedia.org/wiki/Escape_character

    There is probably a more database-centric way of doing this, but I'll leave that to someone else.

    Best Regards,

    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.