[AccessD] Remove non-alphanumeric characters

Foote, Chris Chris.Foote at uk.thalesgroup.com
Thu Apr 8 10:35:39 CDT 2004


Good afternoon all!

I have a requirement to strip a string of all non-alphanumeric characters.
In addition I wanted to change all upper-case characters to lower-case. I
could not find any ready-rolled solution so I've come up with the code
below.

Can anyone think of a more simple way of doing this?

Regards!

Chris Foote (UK)

------------(Code snippet begin)-------------



'--------------------------------------------------------------
' This piece of (almost) original code is based upon M$
' Knowledge Base Article 99938. It removes all non-alphanumeric
' characters from a string. It also converts upper-case letters
' to their lower-case versions. It works by converting the
' incoming characters into the ASCII equivalent checking
' to verify what they are and then converting them back again.
' Chris Foote 08/04/04
'--------------------------------------------------------------
Dim strClean As String
Dim intPos As Integer
Dim strMixed As String
Dim intMixed As Integer

intPos = 1

If IsNull(spAlphaNum) Then Exit Function

For intPos = 1 To Len(spAlphaNum)
    intMixed = Asc(Mid(spAlphaNum, intPos, 1))
        Select Case intMixed
            Case 48 To 57   ' Numeric
                strClean = strClean + Chr(intMixed)
            Case 65 To 90   ' Uppercase Alpha
                strClean = strClean + Chr(intMixed + 32)
            Case 97 To 122   ' Lowercase Alpha
              strClean = strClean + Chr(intMixed)
            Case Else
            
        End Select
Next intPos

fctRemNonAlpha = strClean

End Function



More information about the AccessD mailing list