472,127 Members | 2,130 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

Strip all non alpha characters from a string

All,

Is there such a function that can strip all non alpha ( not between a-z)
characters from a string? I have a function that I currently use that will
strip one character at a time from a string that I tried tweaking without
success. Any help would be much appreciated.

Thanks in advance,
Mark C.
he******@yahoo.com
Nov 13 '05 #1
6 8794
Function StripAlphaChars(strOriginalString As String) As String
Dim intLoop As Integer
Dim strTemp As String
strTemp = strOriginalString
For intLoop = Asc("A") To Asc("Z")
strTemp = Replace(strTemp, Chr(intLoop), "", 1, -1, vbTextCompare)
Next intLoop
StripAlphaChars = strTemp
End Function

--

Ken Snell
<MS ACCESS MVP>

"Mark C" <he******@yahoo.com> wrote in message
news:4d********************@comcast.com...
All,

Is there such a function that can strip all non alpha ( not between a-z)
characters from a string? I have a function that I currently use that will
strip one character at a time from a string that I tried tweaking without
success. Any help would be much appreciated.

Thanks in advance,
Mark C.
he******@yahoo.com

Nov 13 '05 #2
Oops -- Sorry, I misread your post. This will strip numeric characters from
the string. If you want to cover other alpha characters, such as French or
German alpha characters, you can modify the For loop parameters as needed.

Full "width" of ASCII characters is 0 to 255 for Chr(x) function (x = 0 to
255).
Function StripNumberChars(strOriginalString As String) As String
Dim intLoop As Integer
Dim strTemp As String
On Error Resume Next
strTemp = strOriginalString
For intLoop = Asc("0") To Asc("9")
strTemp = Replace(strTemp, Chr(intLoop), "", 1, -1, vbTextCompare)
Next intLoop
StripNumberChars = strTemp
Err.Clear
End Function

"Mark C" <he******@yahoo.com> wrote in message
news:4d********************@comcast.com...
All,

Is there such a function that can strip all non alpha ( not between a-z)
characters from a string? I have a function that I currently use that will
strip one character at a time from a string that I tried tweaking without
success. Any help would be much appreciated.

Thanks in advance,
Mark C.
he******@yahoo.com

Nov 13 '05 #3
There are always, of course, lots of ways of doing these things. Here's
another approach (adapted from Ken's):
Function StripAlphaChars(strOriginalString As String) As String
Dim intLoop As Integer
Dim strTemp As String
Dim strChar As String
strTemp = ""
For intLoop = 1 To Len(strOriginalString)
strChar = Mid$(strOriginalString, intLoop, 1)
Select Case Asc(strChar)
' Upper case chars [A-Z]
Case 65 To 90: strTemp = strTemp & strChar
' Lower case chars [a-z]
Case 97 To 122: strTemp = strTemp & strChar
Case Else
End Select
Next intLoop
StripAlphaChars = strTemp
End Function

HTH,
Randy

"Ken Snell" <kt***********@ncoomcastt.renaetl> wrote in message
news:up**************@TK2MSFTNGP09.phx.gbl...
Oops -- Sorry, I misread your post. This will strip numeric characters from the string. If you want to cover other alpha characters, such as French or
German alpha characters, you can modify the For loop parameters as needed.

Full "width" of ASCII characters is 0 to 255 for Chr(x) function (x = 0 to
255).
Function StripNumberChars(strOriginalString As String) As String
Dim intLoop As Integer
Dim strTemp As String
On Error Resume Next
strTemp = strOriginalString
For intLoop = Asc("0") To Asc("9")
strTemp = Replace(strTemp, Chr(intLoop), "", 1, -1, vbTextCompare)
Next intLoop
StripNumberChars = strTemp
Err.Clear
End Function

"Mark C" <he******@yahoo.com> wrote in message
news:4d********************@comcast.com...
All,

Is there such a function that can strip all non alpha ( not between a-z)
characters from a string? I have a function that I currently use that will strip one character at a time from a string that I tried tweaking without success. Any help would be much appreciated.

Thanks in advance,
Mark C.
he******@yahoo.com


Nov 13 '05 #4
Thanks ken, The function worked perfectly.

Regards,
Mark C.
he******@yahoo.com
"Ken Snell" <kt***********@ncoomcastt.renaetl> wrote in message
news:up**************@TK2MSFTNGP09.phx.gbl...
Oops -- Sorry, I misread your post. This will strip numeric characters from the string. If you want to cover other alpha characters, such as French or
German alpha characters, you can modify the For loop parameters as needed.

Full "width" of ASCII characters is 0 to 255 for Chr(x) function (x = 0 to
255).
Function StripNumberChars(strOriginalString As String) As String
Dim intLoop As Integer
Dim strTemp As String
On Error Resume Next
strTemp = strOriginalString
For intLoop = Asc("0") To Asc("9")
strTemp = Replace(strTemp, Chr(intLoop), "", 1, -1, vbTextCompare)
Next intLoop
StripNumberChars = strTemp
Err.Clear
End Function

"Mark C" <he******@yahoo.com> wrote in message
news:4d********************@comcast.com...
All,

Is there such a function that can strip all non alpha ( not between a-z)
characters from a string? I have a function that I currently use that will strip one character at a time from a string that I tried tweaking without success. Any help would be much appreciated.

Thanks in advance,
Mark C.
he******@yahoo.com


Nov 13 '05 #5
You're welcome.

--

Ken Snell
<MS ACCESS MVP>

"Mark C" <he******@yahoo.com> wrote in message
news:k7********************@comcast.com...
Thanks ken, The function worked perfectly.

Regards,
Mark C.
he******@yahoo.com
"Ken Snell" <kt***********@ncoomcastt.renaetl> wrote in message
news:up**************@TK2MSFTNGP09.phx.gbl...
Oops -- Sorry, I misread your post. This will strip numeric characters

from
the string. If you want to cover other alpha characters, such as French or
German alpha characters, you can modify the For loop parameters as needed.
Full "width" of ASCII characters is 0 to 255 for Chr(x) function (x = 0 to 255).
Function StripNumberChars(strOriginalString As String) As String
Dim intLoop As Integer
Dim strTemp As String
On Error Resume Next
strTemp = strOriginalString
For intLoop = Asc("0") To Asc("9")
strTemp = Replace(strTemp, Chr(intLoop), "", 1, -1, vbTextCompare)
Next intLoop
StripNumberChars = strTemp
Err.Clear
End Function

"Mark C" <he******@yahoo.com> wrote in message
news:4d********************@comcast.com...
All,

Is there such a function that can strip all non alpha ( not between a-z) characters from a string? I have a function that I currently use that

will strip one character at a time from a string that I tried tweaking without success. Any help would be much appreciated.

Thanks in advance,
Mark C.
he******@yahoo.com



Nov 13 '05 #6
> > "Mark C" <he******@yahoo.com> wrote in message
news:4d********************@comcast.com...
All,

Is there such a function that can strip all non alpha ( not between a-z)

Guess I misunderstood. I thought that meant that you might want to strip
characters besides digits, such as punctuation and control characters, as
well.
characters from a string? I have a function that I currently use that will strip one character at a time from a string that I tried tweaking without success. Any help would be much appreciated.

Thanks in advance,
Mark C.
he******@yahoo.com


Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Giampiero Gabbiani | last post: by
22 posts views Thread by ineedyourluvin1 | last post: by
4 posts views Thread by Tim Conner | last post: by
4 posts views Thread by David Beck | last post: by
2 posts views Thread by Brian Henry | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.