[RESOLVED] how to extract plain text from rtf blocks
hi all
how can i extract text from rtf block,
i am using this code
Code:
Private function rtftotext(rtfstring as string) as string
Dim rtf1 As New System.Windows.Forms.RichTextBox
rtf1.Rtf = rtfstring
Dim txt1 As New TextBox
return rtf1.Text
end function
the problem with this code is it loses all enter breaks ( new line breaks).
if comes back correctly as one paragraph. anybody knows how can i keep the new lines while extracting the text ???
thank you
Re: how to extract plain text from rtf blocks
I guess you mean that the final string does not contain the double line break pair of CR and LF.
You could do something like this;
Code:
Private Function rtftotext(ByVal rtfstring As String) As String
Dim rtf1 As New System.Windows.Forms.RichTextBox
rtf1.Rtf = rtfstring
Return RTFToPlainText(rtf1)
End Function
Private Function RTFToPlainText(ByVal rtfbox As RichTextBox) As String
Dim str As String = String.Empty
For Each line As String In rtfbox.Lines
str += line & vbCrLf
Next
Return str
End Function
Re: how to extract plain text from rtf blocks
thank you very much for your help, it worked just fine.
btw :
i didnt know the rtf has a lines collection :blush:
thank you again