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.
Printable View
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.
Easiest would be using Replace
eg.
What do you mean by thisCode:Text1.Text = Replace(Text1.Text, "<i>", "", , , vbTextCompare)
Text1.Text = Replace(Text1.Text, "<b>", "", , , vbTextCompare)
:confused:Quote:
By the way, the data is entered all at once.)
:wave:
This is what I use in the VBForum Ticker program to remove all the HTML junk.
IIRC it's slightly modified version from this example here on PSC.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
If someone has faster/better one, please post!
Thanks guys. I used Replace.
You are Welcome.
Now you could help us by pulling Thread Tools and Marking the Thread Resolved .;)
:wave: