Click here to Skip to main content
15,896,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a report to pull RTF data from SQL into an RDL file (SSRS). At first I used a VB.Net function to pull that data into a RichTextBox and convert it to text. Here is the code I used:

Public Function ConvertRtfToText(ByVal input As String) As String
 
Dim returnValue As String = String.Empty
 
Using converter As New System.Windows.Forms.RichTextBox()
 
converter.Rtf = input.Trim
 
returnValue = converter.Text
 
End Using
 
Return returnValue
 
End Function


This worked well, except for the fact the hidden text (\v tag) was displayed. I cannot seem to figure out how to remove the lines that are hidden, or just hide them. If I create a RTF file and paste the string in there, that stuff is hidden, but converting to text does not work. I tried the what I had below (filtering on revised data instead of hidden) and then I realized that the .Line Method puts everything to text and you lose the tags to filter on.

How do I filter out the hidden/revised area? I have the example of RTF data provided as well (a portion of it anyways). Thank you for any input in advance. I have been struggling with this for days.

Public Function ConvertRtfToText(ByVal input As String) As String
Dim returnValue As String = String.Empty

Using converter As New System.Windows.Forms.RichTextBox()
converter.rtf = input.Trim

Dim txt() As String = converter.Lines

        For Each s As String In txt
            If (txt([s]).Contains("\revised")) Then
                txt([s]) = String.Empty
            End If

        Next

converter.Lines = txt

returnValue = converter.Text
 
End Using
 
Return returnValue
End Function


\brdrw20\brdrcf2\clbrdrt\brdrs \brdrw20\brdrcf2\clbrdrr\brdrs \brdrw20\brdrcf2\clbrdrb\brdrs \brdrw20\brdrcf2\cellx3888\pard\intbl \ql {\*\bkmkstart bk12433203060}{\*\bkmkend bk12433203060}\pard\intbl\fi-468\li720\f2\fs20 \'b7 \f1 \f1\fs20 \b \escp ED Departure Time\b0 \cell \clbrdrl\brdrs \brdrw20\brdrcf2\clbrdrt\brdrs \brdrw20\brdrcf2\clbrdrr\brdrs \brdrw20\brdrcf2\clbrdrb\brdrs \brdrw20\brdrcf2\cellx8784\pard\intbl \ql \f1\fs20 \escp 10:22\cell \row \v\revised\trowd\trgaph108\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3\trkeep\trleft0\clbrdrl\brdrs \brdrw20\brdrcf2\clbrdrt\brdrs \brdrw20\brdrcf2\clbrdrr\brdrs \brdrw20\brdrcf2\clbrdrb\brdrs \brdrw20\brdrcf2\cellx3888\pard\intbl \ql \cell \clbrdrl\brdrs \brdrw20\brdrcf2\clbrdrt\brdrs \brdrw20\brdrcf2\clbrdrr\brdrs \brdrw20\brdrcf2\clbrdrb\brdrs \brdrw20\brdrcf2\cellx8784\pard\intbl \ql \ulnone\b0\cf3\strike \f1\fs20 \escp 11:22\strike0\cf1\cell \row \v0\revised0\pard \trowd\trgaph108\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3\trkeep\trleft0\clbrdrl\brdrs \brdrw20\brdrcf2\clbrdrt\brdrs \brdrw20\brdrcf2\clbrdrr\brdrs \brdrw20\brdrcf2\clbrdrb\brdrs  
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900