0

I have a RTF textbox that contains multiline text. I would like to extract the text only from this box to put in an e-mail.

I know that RTFBox.Text will return the plain text but it seems that it strips out the CRLF's as well and I need to keep those for the e-mail.

Thanks in advance for any help.

4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Reverend Jim
0

Hi,

I think you need to get the actual RTF back then parse the rich text and strip out any RTF coding and replace the RTF new Line character with vbcrlf.

It's been a while since I looked at RTF text so I'm not 100% sure of the syntax. Here is an example though of when I cleaned up Word generated "HTML"

Function CleanHTML (byref Input as String) AS String
Dim bInTag as boolean = false
dim sChar, Tagcode, Output as string
dim i as integer


for i =1 to len(Input)
        schar = mid(Input,i,1)
        if not bInTag then
            if schar ="<" then
                binTag =true
            else
                Output += schar
            end if
        else
            if schar = ">" then
                bInTag = False
                if Instr(TagCode, "</") <> 0 then
                    Output += TagCode
                elseif Instr(TagCode, <B) <> 0 Then
                    Output += "<b>"
                    'etc.
                end if
                TagCode=""
            else
                Tagcode += UCASE(schar)
            end if
        End if

next

As I said that's roughly what I did for HTML but I'm sure you could do somethng similar for RTF.

0

Textboxes use only the LF character. This is one way to handle it.

  Dim lines() As String = RichTextBox1.Lines
  'initialize stringbuilder to textlength + num lines  (this adds space for VbCr)
  Dim sb As New System.Text.StringBuilder(RichTextBox1.TextLength + lines.Length + 20)
  For Each l As String In lines
     sb.AppendLine(l) 'add line with CrLF appended
  Next
  Dim EmailMessage As String = sb.ToString

Edited by TnTinMN: mod code

0

Wouldn't it also work if you just replaced lf with crlf as in

RichTextBox1.Text.Replace(vbLf,vbCrLf)

Edited by Reverend Jim

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.