Question Singing the RTF encoding blues...

gchq

Well-known member
Joined
Dec 14, 2007
Messages
168
Programming Experience
10+
Here is the grand plan. Save the RTF from a RichTextBox to a db, then using the RTF coding split the text to use with iTextSharp..

After taking out the top part of the encoding I start on the paragraphs like this:-

VB.NET:
Dim i As Integer = vString.IndexOf("\fs") + 3
        vEndIndex = vString.IndexOf("\par", i + 1)
        Do While (i <> -1) And (vEndIndex <> -1)
                       vChars = vEndIndex - (i + 2)
            Dim vReturnString As String = vString.Substring(i + 2, vChars)
           
            TempParagraph(vReturnString)
            i = vString.IndexOf("\par", i + 1)
            vEndIndex = vString.IndexOf("\par", i + 1)
        Loop

and break out any bold (I'll be working on other formats once I get this part working)

VB.NET:
Private Sub TempParagraph(ByVal Paragraph As String)
        If BoldFwd = 1 Then
            Paragraph = "\b " & Paragraph
            If Not Paragraph.Contains("\b0") Then
                Paragraph += "\b0"
            End If
        End If
        If Paragraph.Substring(0, 3) = "\b0" Then
            Paragraph.Remove(0, 3)
            BoldFwd = 0
        End If
        If Paragraph.Contains("ard\fs") Then
            'This is the last paragraph
            Dim vLastIndex As Integer = Paragraph.IndexOf("ard\fs")
            Paragraph = Paragraph.Substring(0, vLastIndex)
        End If
        If Not Paragraph.Contains("\b ") And Paragraph.Contains("\b0") Then
           MessageBoxIcon.Information)
            BoldFwd = 0
            Paragraph.Replace("\b0", "##")
        End If
        
        If Paragraph.Contains("\b ") Then
            If Not Paragraph.Contains("\b0") Then
                Paragraph += "\b0"
                BoldFwd = 1
            Else
                BoldFwd = 0
            End If

            Dim vChars As Integer = 0
            Dim i As Integer = Paragraph.IndexOf("\b ")
            Dim vEndIndex As Integer = Paragraph.IndexOf("\b0") '- 1
            'If i <> -1 And vEndIndex = -1 Then
            '    Paragraph += "\b0"
            '    vEndIndex = Paragraph.IndexOf("\b0")
            '    BoldFwd = 1
            'Else
            '    BoldFwd = 0
            'End If
            Dim vBold As String = ""
            Dim vTotal As Integer = Paragraph.Length
            Do While (i <> -1)
                vChars = vEndIndex - (i + 2)
                vBold = Paragraph.Substring(i + 2, vChars)
                i = Paragraph.IndexOf("\b ", i + 1)
                vEndIndex = Paragraph.IndexOf("\b0", vEndIndex + 1)
               Loop

        Else
            If Paragraph = "" Then
                Paragraph = "##BlankLine##"
            End If

            'AppBox.Show(Paragraph, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

Everything works fine until there is a blank extra line, then I get "ar□□" inserted into the string, and can't find any way to get rid of it (including String.Replace(ControlChars))

Any ideas?

Thanks
 
Dah! The first paragraph starts with \fs then picks up \par so the first line was OK, then it went astray!

Sorted
 
Back
Top