Extracting first 1 or 2 nymbers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there an easy way to extract the first 1 or 2 numbers from a string mixed
string. I need to extract the 4 from 4-jh or 4 jh or 4 jh or extract 56 from
as similar string. the problem is I never know what the first non-numeric
character will be so it seems I have to test for all 26 characters. All i
want is the first n numeric characters.

thanks for any and all help
 
Hi Steve -

If the n characters in the string will always be numeric then you can use the
val() function. Example:

x = "4 jh"
? val(x)
4

HTH - Bob
 
Hi Bob and Steve,

This will work most of the time but will give unexpected results if the
string starts with digits, then has a letter d or e (or D or E), and
then one or more digits:

? Val("56D5")
5600000


One (of many) alternatives is to use a regular expression, e.g. with the
rgxExtract() function at
http://www.j.nurick.dial.pipex.com/Code/index.htm

?rgxextract("56D5", "^\d+")
56
 
John -

Good catch! Had me scratching my head for a while until I realized the
string(s) in question were being interpreted as scientific notation. Am
going to have to brush-up on regular expressions.

Best wishes - Bob

John said:
Hi Bob and Steve,

This will work most of the time but will give unexpected results if the
string starts with digits, then has a letter d or e (or D or E), and
then one or more digits:

? Val("56D5")
5600000

One (of many) alternatives is to use a regular expression, e.g. with the
rgxExtract() function at
http://www.j.nurick.dial.pipex.com/Code/index.htm

?rgxextract("56D5", "^\d+")
56

Hi Steve -
[quoted text clipped - 14 lines]
 
Back
Top