RTF word parsing (Experts with RTF)

I am using many rtf word processors in my .net application. They are a thrid party tool. If you are familiar with RTF then you know that you can have a large paragraph of RTF which is all formatting and no text.

Example:

{\rtf1\ansi\ansicpg1252\uc1\deff0{\fonttbl {\f0\fswiss\fcharset0\fprq2 Arial;} {\f1\fswiss\fcharset0\fprq2 Microsoft Sans Serif;} {\f2\froman\fcharset2\fprq2 Symbol;}} {\colortbl;\red0\green0\blue0;\red255\green255\blue255;} {\stylesheet{\s0\itap0\nowidctlpar\f0\fs24 [Normal];}{\*\cs10\additive Default Paragraph Font;}} {\*\generator TX_RTF32 13.0.501.502;} \deftab1134\paperw12240\paperh15840\margl1138\margt1138\margr1138\margb1138\widowctrl\pard\itap0\nowidctlpar\plain\f1\fs20 \par }

Does anyone know how a to strip the rtf down to text, to check if its empty or not?

Thank you

[836 byte] By [Rohrer] at [2008-1-10]
# 1

I didn't understand much what you want to do. but "RTF word Parsing" if you want to detect that an RTF file is correct then load it, like that

Try

rtb.load (file, rtfformat)

Here if the file isn't RTF the control will return an error

Catch ex as exception

msgbox "incorrect file format"

end try

OmarAbid at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
The Q&D approach is to assign this string to an RTB and verify its Text property:

Private Shared mRtb As New RichTextBox ' RTB cache so we don't have to recreate the RTB over and over again
Public Shared Function Rtf2Text(ByVal rtf As String) As String
mRtb.Rtf = rtf
Return mRtb.Text
End Function

nobugz at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

I don't reall care if the rtf is correct, I care that there is TEXT in the RTF.

I want to be able to tell that there is text in the rtf and that the rtf is just formatting.

I don't have any controls at my disposal, such as richtextbox.

Thank you

Brandon

Rohrer at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4
You don't get it. If there's no TEXT in the rtf, the function returns an empty string.
nobugz at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5

The function that you are using is from a control. I do not have access to this control. This is a class project. I don't have access to anything in windows.forms.

I will see if i can take the code from .load using reflector.

Rohrer at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6
Project + Add Reference, select System.Windows.Forms. Put "using System.Windows.Forms" at the top of your source code file.
nobugz at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...