Welcome to WebmasterWorld Guest from 126.96.36.199
Forum Moderators: open
1) I have a string in a form of variable length - max 30 chars
2) Each and every string always contains a two digit integer number
3) The actual integer number varies from one string to another, and the value is unknown
4) The position of the integer number varies within the string
I need to search the string for the integer and then use it as a variable for other calculations.
1) Today is Saturday 24th
2) No. 12 Ridge Road
3) Sunday 16th December
4) I am 43 years old
5) I moved house on the 30th
and a warm welcome to these forums. ;)
try it like this...
'Today is Saturday 24th',
'No. 12 Ridge Road',
'Sunday 16th December',
'I am 43 years old',
'I moved house on the 30th'
alert('string '+c+ ' containtains the number '+matches[c]);
Did you work it out or was a case of using "standard" functions such as .match?
Yes that is correct and, of course, a basic RegExpression. ;)
Hi there Dabrowski,
You should probably use /\d+/ as the regexp as this will match any number, not just 2 digits.
That is true, but I did not use it as the OP specifically said ...
Each and every string always contains a two digit integer number
I now not only find the integer but find where it starts in the string and slice the first part of for another search.