...

View Full Version : Reg Exp or otherwise?



ScottInTexas
10-15-2003, 03:20 PM
What is the best way to extract a single number from within a string? I think maybe a reg expression, but I am not real well versed in them.

liorean
10-15-2003, 03:31 PM
How is the number embedded in the string? What kind of number is it - may it contain decimal point, commas or spaces? Minus/plus?

Most likely, a regex is your best aproach, unless it's the first part of the string where parseInt/parseFloat would be better choices.

ScottInTexas
10-15-2003, 04:00 PM
The number would be a positive integer somewhere within the string. You are right about the regex. I'll research it and see if I can learn to use it properly.

Thanks for your help.

liorean
10-15-2003, 04:08 PM
var iNumber=parseInt(sString.match(/\d+/));

ScottInTexas
10-15-2003, 04:49 PM
Perfect perfect perfect. I just love this forum!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum