Here is a function to remove or escape any quotes (3 types) or apostrophes (3 types)
Code:
Public Function CleanQuotes( ByVal strDirty, boolRemove )
strData = Replace( Replace( strDirty, Chr(147), Chr(34) ), Chr(148), Chr(34) )
strData = Replace( Replace( strData, Chr(146), Chr(39) ), Chr(96), Chr(39) )
If Not CBool( boolRemove ) Then
strData = Replace( strData, Chr(39), String( 2, Chr(39) ) )
strData = Replace( strData, Chr(34), Chr(39) & Chr(34) )
ElseIf CBool( boolRemove ) Then
strData = Replace( strData, Chr(39), Chr(32) )
strData = Replace( strData, Chr(34), Chr(32) )
Do While InStr( 1, strData, String( 2, Chr(32) ) ) > 0
strData = Replace( strData, String( 2, Chr(32) ), Chr(32) )
Loop
End If
CleanQuotes = Trim( strData )
End Function
Sample:
Code:
' to escape for SQL statements
strClean = CleanQuotes( strDirtyData, False )
'or to remove the quotes entirly
strClean = CleanQuotes( strDirtyData, True )
And a function to remove tabs, newlines, carriage returns, and extra spaces.
Code:
Public Function CleanString( ByVal strDirty )
strData = Trim( strDirty )
arrRemove = Array( Chr(9), Chr(10), Chr(13) )
For Each Item In arrRemove
strData = Replace( strData, Item, Chr(32) )
Next
Do While InStr( 1, strData, String( 2, Chr(32) ) )
strData = Replace( strData, String(2, Chr(32) ), Chr(32) )
Loop
CleanString = Trim( Replace( strData, Chr(62) & Chr(32) & Chr(60), Chr(62) & Chr(60) ) )
End Function
Sample:
Code:
strClean = CleanString( strDirtyData )
A function like String() except that it supports multiple character strings to repeat.
Code:
Public Function NString( lngQuanity, strExpression )
For Idx = 1 To CLng( lngQuanity )
strData = strData & strExpression
Next
NString = strData
End Function
Sample:
Code:
strManyBlahs = NString( 10, "blah " )
A function to get the data between 2 tags ("<title>blah</title>" for example)
Code:
Public Function TagData( ByVal strTag, ByVal strSource )
lngStart = InStr( 1, LCase( strSource ), Chr(60) & LCase( strTag ) )
If lngStart > 0 Then
lngStart = InStr( lngStart, LCase( strSource ), Chr(62) ) + 1
lngStop = InStr( lngStart, LCase( strSource ), Chr(60) & Chr(47) & LCase( strTag ) & Chr(62) )
If lngStart > 0 And lngStop > lngStart Then strData = Trim( Mid( strSource, lngStart, lngStop - lngStart ) )
End If
TagData = strData
End Function
Sample:
Code:
'this will return the <title> value from the string
strTitle = TagData( "title", strHTMLorXML )
Maybe you can tell that I do a lot of parsing work?
Bookmarks