Removing letters from strings

  • Thread starter Thread starter K
  • Start date Start date
K

K

Good day,
How do I remove the letters from a string of text.
is this possible to do with an expression in a query?
 
Forgot to add, the string contains numbers which are all I want to see from a
string. For example - Sting= FS30402371188A26924 would like only to return
the 304023711882694
 
K said:
Forgot to add, the string contains numbers which are all I want to see from a
string. For example - Sting= FS30402371188A26924 would like only to return
the 304023711882694


Create a function to do it:

Public Function ExtractDigits(s As String) As String
Dim k As Long

For k = 1 To Len(s)
If Mid(s, k) Like "[0-9]"
ExtractDigits = ExtractDigits & Mid(s, k)
End If
Next k
End Function
 
Pardon me, but I think you missed one thing in the routine. Don't you need
the third argument set to 1 in both places you are using Mid. Also I think
you need a THEN at the end of the IF line.

Public Function ExtractDigits(s As String) As String
Dim k As Long

For k = 1 To Len(s)
If Mid(s, k,1) Like "[0-9]" THEN
ExtractDigits = ExtractDigits & Mid(s, k,1)
End If
Next k
End Function


--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Marshall Barton said:
K said:
Forgot to add, the string contains numbers which are all I want to see
from a
string. For example - Sting= FS30402371188A26924 would like only to return
the 304023711882694


Create a function to do it:

Public Function ExtractDigits(s As String) As String
Dim k As Long

For k = 1 To Len(s)
If Mid(s, k) Like "[0-9]"
ExtractDigits = ExtractDigits & Mid(s, k)
End If
Next k
End Function
 
John said:
Pardon me, but I think you missed one thing in the routine. Don't you need
the third argument set to 1 in both places you are using Mid. Also I think
you need a THEN at the end of the IF line.

Public Function ExtractDigits(s As String) As String
Dim k As Long

For k = 1 To Len(s)
If Mid(s, k,1) Like "[0-9]" THEN
ExtractDigits = ExtractDigits & Mid(s, k,1)
End If
Next k
End Function


Thanks for catching those omissions John.
 
Back
Top