0

I want to use a RichTextBox (WinForms) to manipulate plain text, so I can use rich text features for highlighting.

Plain text will be loaded to RichTextBox, edited and saved. Rich text features are only for immediate work and will not be stored.

Format of plain text in database is utf8.

I am worried there might be some unwanted change in the text string during this process:

richTextBox1.Text = LoadText();
//user and program manipulate the text, rich text features are used
SaveText(richTextBox1.Text);

Thank you.

Edit:

More specifically:

  • Is there any implicit conversion when loading utf8 plain text in a RichTextBox?
  • Will the Text property of a RichTextBox be identical to the string in the database if only formatting is changed, that is, can the use of rich text features affect the naked plain text string in property Text?
  • Is there any limitation of the rtf format which may affect the underlying plain text?

For instance:

It seems RichTextBox changes "\r\n" to "\n" (link). This is what I would call an unwanted change. If it is only this, I could accept it or avoid it somehow, but are there other potential changes?

I know Rtf can handle any utf8 characters prefixing "\u", but is it reliable? Shall it be able to handle any character if given the appropriate font?

Community
  • 1
  • 1
Dil
  • 632
  • 7
  • 13
  • Have you already tried it yourself before asking in SO. If yes can you please copy/paste the text that get changed like in BEFORE AFTER version – HatSoft Jun 24 '12 at 23:08
  • You don't have to worry to much about that snippet causing trouble, there are very few ways it could even compile. Spend a bit of effort to make your question understandable. If you don't then why would we? – Hans Passant Jun 25 '12 at 00:05
  • @HatSoft, I will surely compare input and output. I still haven't decided to use RichTextBox and just wanted to anticipate any possible problems. Maybe this is not a good question. In case it were useful, I have added some specific questions. – Dil Jun 25 '12 at 09:39
  • @HansPassant, "there are very few ways it could even compile"? Why is that? I only used LoadText() and SaveText() to mean "extract string from database" and "save string to database". It would not be exactly like this in the code, since other objects are involved. I did spend time to word my question in a simple and understandable way. Just maybe it is too general or trying to anticipate problems which do not exist? – Dil Jun 25 '12 at 09:42

0 Answers0