-
June 13th, 2011, 10:42 AM
#1
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?
-
June 14th, 2011, 12:28 AM
#2
Re: RichTextBox + MySQL String and '\n' problem...
try:
rtbText.Text.Replace("\n", "\n\r");
or
rtbText.Text.Replace("\n", "\r\n");
-
June 14th, 2011, 01:57 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|