Results 1 to 5 of 5

Thread: [RESOLVED] Remove HTML Tags

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2007
    Posts
    118

    Resolved [RESOLVED] Remove HTML Tags

    Hey,

    I have a rich text box, and I want it so that if any text is entered; it will remove any <i> or <b> tags. How do I do this? (By the way, the data is entered all at once.)

    Thanks.

  2. #2
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: Remove HTML Tags

    Easiest would be using Replace
    eg.

    Code:
    Text1.Text = Replace(Text1.Text, "<i>", "", , , vbTextCompare)
        Text1.Text = Replace(Text1.Text, "<b>", "", , , vbTextCompare)
    What do you mean by this

    By the way, the data is entered all at once.)


    IIF(Post.Rate > 0 , , )

  3. #3
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Remove HTML Tags

    This is what I use in the VBForum Ticker program to remove all the HTML junk.

    Code:
    Private Function CleanHtml(sourceStr As String) As String
    ' // remove html tags //
      Dim targetStr As String, lenOfString As String, currentChar As String
      Dim currentRunningTag As String, excludeList As String, lineBreak As String
      Dim openedWith As String, closeWith As String
      Dim opened As Boolean
      Dim charPos As Long, j As Long
      Const openingChars As String = "<&"
      Const closingChars As String = ">;"
      
      excludeList = "<TITLE>"
      lineBreak = "</P><BR></TD>"
      
      lenOfString = Len(sourceStr)
      For j = 1 To lenOfString
         currentChar = Mid(sourceStr, j, 1)
         If opened = True Then
            currentRunningTag = currentRunningTag & currentChar
            If UCase(currentChar) = UCase(closeWith) Then
              opened = False
              If InStr(UCase(lineBreak), UCase(currentRunningTag)) > 0 Then targetStr = targetStr & vbNewLine
            End If
         ElseIf InStr(UCase(openingChars), UCase(currentChar)) > 0 Then
            charPos = InStr(UCase(openingChars), UCase(currentChar))
            closeWith = Mid(closingChars, charPos, 1)
            opened = True
            openedWith = currentChar
            currentRunningTag = currentChar
         Else
            'targetStr = targetStr & currentChar
            If InStr(UCase(excludeList), UCase(currentRunningTag)) = 0 Then targetStr = targetStr & currentChar
         End If
      Next j
      CleanHtml = targetStr
    End Function
    IIRC it's slightly modified version from this example here on PSC.

    If someone has faster/better one, please post!

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2007
    Posts
    118

    Re: Remove HTML Tags

    Thanks guys. I used Replace.

  5. #5
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: Remove HTML Tags

    You are Welcome.

    Now you could help us by pulling Thread Tools and Marking the Thread Resolved .

    IIF(Post.Rate > 0 , , )

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