|
-
Mar 23rd, 2008, 05:01 AM
#1
Thread Starter
Lively Member
[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.
-
Mar 23rd, 2008, 05:22 AM
#2
Frenzied Member
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.)

-
Mar 23rd, 2008, 05:33 AM
#3
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!
-
Mar 23rd, 2008, 07:06 AM
#4
Thread Starter
Lively Member
Re: Remove HTML Tags
Thanks guys. I used Replace.
-
Mar 23rd, 2008, 07:35 AM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|