RichTextBox + MySQL String and '\n' problem...
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

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

  1. #1
    Join Date
    Jun 2011
    Posts
    1

    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
    Posts
    3

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

    try:

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

  3. #3
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,005

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

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

    Code:
    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.

    Victory?
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center