How to Strip special characters from a given String
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 'String Manipulation - How to Strip special characters from a given String Option Explicit 'To strip special characters (ASCII value above 127) from a string. 'This function strips all characters with an ASCII value of 128 or higher from a string. Public Function StripSpecialCharacters(ByVal sExpression As String) As String Dim sOrigString As String, sResult As String, sChar As String Dim lLen As Long, lCount As Long, lCtr2 As Long lLen = Len(sExpression) sOrigString = Space$(lLen) sOrigString = sExpression sResult = sOrigString lCtr2 = 1 For lCount = 1 To lLen sChar = Mid(sOrigString, lCount, 1) If Asc(sChar) < 128 Then Mid(sResult, lCtr2, 1) = sChar lCtr2 = lCtr2 + 1 End If Next lCount If lCtr2 > 1 Then sResult = Left(sResult, lCtr2 - 1) Else sResult = "" End If StripSpecialCharacters = sResult End Function |