tags:

views:

3857

answers:

5

In a C# console app I have the need to extract the text from an RTF string, add some more text to it, and then convert it back into RTF. I have been able to do this using the System.Windows.Forms.RichTextBox class, but I find it a bit odd to use a Forms control in a non-Forms app. Any better way to do this?

A: 

It depends on what you mean by 'better'. You are already using the simplest and easiest way of doing it.

samjudson
+1  A: 

Please see discussion on this topic:

http://stackoverflow.com/questions/20450/cleaning-up-rtf-text

Vincent
+1  A: 

Doing anything with RTF is pretty difficult unless you're using the windows forms. As stated above, using forms is the easiest way to go.

You could write something yourself, but the RTF spec is pretty complicated.
http://www.biblioscape.com/rtf15_spec.htm

Or you could use a conversion DLL / ActiveX object of which there is a large number available. http://www.sautinsoft.com/

Or - If you're doing this from Linux, there are also tools available. A cursory glance throws up UnRTF http://www.gnu.org/software/unrtf/unrtf.html

I haven't included stuff to turn text back to RTF because I think the RTF specification treats and formats text correctly.

seanyboy
A: 

I think you should just shake this feeling of "odd". There's nothing odd about it.

Svend
A: 

There is nothing wrong with using an user-interface control in a console application or even in a web application. The Windows controls are part of the .NET Framework, might as well use them. These controls do not need to be hosted in "forms" in order to work.

Reinventing the wheel, using DLL/ActiveX/OCX, and using Linux are simply not practical answers to your question. The better way is...do what you know. There is actually a performance and maintainence benefit to using existing framework methods then using the suggested alternatives.

AMissico