[AccessD] Remove non-alphanumeric characters

Andy Lacey andy at minstersystems.co.uk
Thu Apr 8 11:55:07 CDT 2004


Well personally I'd find it easier to read if you just compared characters,
so. Also, as long as your Option Compare doesn't cause case-sensitive
comparisoins, you need only test for a-z once.

For intPos = 1 To Len(spAlphaNum)
strChar = Mid(spAlphaNum, intPos, 1)
Select Case strChar
Case "0" To "9"   ' Numeric
strClean = strClean + strChar
Case "a" To "z"   ' Uppercase Alpha
strClean = strClean + Ucase(strChar)
Case Else
End Select
Next intPos

--
Andy Lacey
http://www.minstersystems.co.uk



--------- Original Message --------
From: Access Developers discussion and problem solving
<accessd at databaseadvisors.com>
To: 'Access Developers discussion and problem solving'
<accessd at databaseadvisors.com>
Subject: [AccessD] Remove non-alphanumeric characters
Date: 08/04/04 15:39

>
> 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
> --
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
>
>
>
>

________________________________________________
Message sent using UebiMiau 2.7.2




More information about the AccessD mailing list