Results 1 to 3 of 3

Thread: [RESOLVED] how to extract plain text from rtf blocks

  1. #1

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Resolved [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

  2. #2
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    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

  3. #3

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    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


    thank you again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width