Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding numbers in a string

Status
Not open for further replies.

don2241

IS-IT--Management
Jun 1, 2001
57
AU
Hi!

If I have a string that looks something like this:

abcd12345efgh

How do I find the number values from the string.
Keep in mind that the string is dynamic, next time the string could look like: "sdfjl sl kd432424323sl flsj" although the numbers are always together.
I'm looking for a method that can take any type of string as a parameter and find the numbers in that string.

Thank you for any help
 
Try something like this...

Private Function GetNumbersFromString(ByVal sString As String) As String

Dim i As Integer
Dim sResult As String
Dim sSingleChar As String

For i = 1 To Len(sString)
sSingleChar = Mid$(sString, i, 1)
If IsNumeric(sSingleChar) Then
sResult = sResult & sSingleChar
End If
Next i

GetNumbersFromString = sResult
End Function Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
Have you looked into using a Regular Expression for this? Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I'll be more specific. I have an MS Access db with 10000 products in it. However the description field has the suppliers code in it:

xyz bolts 100x230mm bla bla 2309 bla bla

I wish to extract the "2309" from this string. I was expecting to use the InStr() function with a #### type of wildcard to get the sequence of 4 numbers out of the string.
 
If you perform a keyword search in the forum for Regular Expressions, you should find considerably more information, as well as numerous examples of the RegExp object. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
If there is any possability that another substring will be of the same pattern, you need to take some extra precaution to assure that the [supplier code] is taken as the correct substring.

Regular Expression, or most any generic procedure will probably be a necessary - but not sufficient part of the overall process.

One additional step will be to chack that the extracted substring(s) are a valid [supplier code]. Where there is ONLY one such sub string, it may be (prbably is) reasonable to assume that the extracted substring is the [supplier code]. Where multiple matches occur, you will ne additional processing.

A recordset w/ 10K records in the apparent free form would be expected (at least by me) to include a large variation in the individual field content. If, for example, a standard UPC bar code were entered, and the string of four consecutive numerics were the search criteria, the porcess would return numerous matches. Adding the leading trailing 'white space' fileters probably helps, but does not eliminate the potential for impropper extraction, as there might be other instances of four concecutive numeric characters.

Without considerable additional information (or actual review of the information available), it is difficult to impossible to be sure that there is any foolproof method which can be totally 'autometed'. I would suggest that the goals of the process be thoroughly reviewed, with at least a thought to the extraction of the [suplier code] only for those instances which are totally unambigious, and the refferal of the remainder to clerical (i.e. Human) processing.

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top