By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,649 Members | 2,154 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,649 IT Pros & Developers. It's quick & easy.

Strip all non alpha characters from a string

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
> > "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.