Re: Trimming and clensing a string
- From: "LGC" <pro3carp3@xxxxxxxxx>
- Date: Wed, 8 Jun 2005 09:23:10 -0500
> Basically, is there an easy way of removing all non-numeric characters
from
> a string?
The following function will remove all non-numeric characters from a string:
Public Function NumericOnly(sSource As String) As String
Dim BytesIn() As Byte
Dim BytesOut() As Byte
Dim LenBytes As Integer
Dim IdxIn As Integer
Dim IdxOut As Integer
If Nz(sSource, "") = "" Then
NumericOnly = ""
Exit Function
End If
BytesIn() = StrConv(sSource, vbFromUnicode)
LenBytes = UBound(BytesIn)
ReDim BytesOut(0 To LenBytes)
For IdxIn = 0 To LenBytes
If BytesIn(IdxIn) > 47 And BytesIn(IdxIn) < 58 Then
BytesOut(IdxOut) = BytesIn(IdxIn)
IdxOut = IdxOut + 1
End If
Next
NumericOnly = StrConv(BytesOut, vbUnicode)
End Function
-LGC
.
- References:
- Trimming and clensing a string
- From: NH
- Trimming and clensing a string
- Prev by Date: Re: msgbox responses
- Next by Date: Re: msgbox responses
- Previous by thread: Trimming and clensing a string
- Next by thread: Re: Trimming and clensing a string
- Index(es):
Relevant Pages
|