dbTalk Databases Forums  

Strip all non alpha characters from a string

comp.database.ms-access comp.database.ms-access


Discuss Strip all non alpha characters from a string in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ken Snell
 
Posts: n/a

Default Re: Strip all non alpha characters from a string - 07-23-2004 , 07:54 AM






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" <hereinde (AT) yahoo (DOT) com> wrote

Quote:
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.
hereinde (AT) yahoo (DOT) com





Reply With Quote
  #2  
Old   
Ken Snell
 
Posts: n/a

Default Re: Strip all non alpha characters from a string - 07-23-2004 , 08:05 AM






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" <hereinde (AT) yahoo (DOT) com> wrote

Quote:
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.
hereinde (AT) yahoo (DOT) com





Reply With Quote
  #3  
Old   
Mark C
 
Posts: n/a

Default Strip all non alpha characters from a string - 07-23-2004 , 09:04 AM



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.
hereinde (AT) yahoo (DOT) com



Reply With Quote
  #4  
Old   
Randy Harris
 
Posts: n/a

Default Re: Strip all non alpha characters from a string - 07-23-2004 , 10:00 AM



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" <kthsneisllis9 (AT) ncoomcastt (DOT) renaetl> wrote

Quote:
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" <hereinde (AT) yahoo (DOT) com> wrote in message
news:4dadnSgH-t__b53cRVn-jA (AT) comcast (DOT) 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.
hereinde (AT) yahoo (DOT) com







Reply With Quote
  #5  
Old   
Ken Snell
 
Posts: n/a

Default Re: Strip all non alpha characters from a string - 07-24-2004 , 01:19 PM



You're welcome.

--

Ken Snell
<MS ACCESS MVP>

"Mark C" <hereinde (AT) yahoo (DOT) com> wrote

Quote:
Thanks ken, The function worked perfectly.

Regards,
Mark C.
hereinde (AT) yahoo (DOT) com


"Ken Snell" <kthsneisllis9 (AT) ncoomcastt (DOT) renaetl> wrote in message
news:upsTuWLcEHA.1596 (AT) TK2MSFTNGP09 (DOT) 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" <hereinde (AT) yahoo (DOT) com> wrote in message
news:4dadnSgH-t__b53cRVn-jA (AT) comcast (DOT) 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.
hereinde (AT) yahoo (DOT) com









Reply With Quote
  #6  
Old   
Mark C
 
Posts: n/a

Default Re: Strip all non alpha characters from a string - 07-24-2004 , 03:22 PM



Thanks ken, The function worked perfectly.

Regards,
Mark C.
hereinde (AT) yahoo (DOT) com


"Ken Snell" <kthsneisllis9 (AT) ncoomcastt (DOT) renaetl> wrote

Quote:
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" <hereinde (AT) yahoo (DOT) com> wrote in message
news:4dadnSgH-t__b53cRVn-jA (AT) comcast (DOT) 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.
hereinde (AT) yahoo (DOT) com







Reply With Quote
  #7  
Old   
Randy Harris
 
Posts: n/a

Default Re: Strip all non alpha characters from a string - 07-24-2004 , 07:18 PM



Quote:
"Mark C" <hereinde (AT) yahoo (DOT) com> wrote in message
news:4dadnSgH-t__b53cRVn-jA (AT) comcast (DOT) 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.

Quote:
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.
hereinde (AT) yahoo (DOT) com




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.