Wednesday, August 18, 2010

Clean the string

Function CleanTheString(theString)
'Remove all non Alpha numeric characters from a string. This will include spaces. If you want to keep a character, add it to the strAlphaNumeric string below
'msgbox thestring
strAlphaNumeric = "-#.'()/,_; :0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 'Used to check for numeric characters.
For I = 1 To Len(theString)
strChar = Mid(theString, I, 1)
If InStr(strAlphaNumeric, strChar) Then
CleanedString = CleanedString & strChar
End If
Next
'msgbox cleanedstring
CleanTheString = CleanedString
End Function

No comments:

Post a Comment