Author
parseInt method
Gina vernon
Ranch Hand
Joined: Jan 16, 2009
Messages: 56
posted Feb 05, 2010 11:40:57
Hi,
I have the following code that does not run when I use the parseInt method:
Am I using the method right?
Thanks.
Eric Pascarello
author
Sheriff
Joined: Nov 08, 2001
Messages: 13569
posted Feb 05, 2010 12:13:39
indexOf returns a number, so why are you using parseInt to start with?
Eric
Race Schedule for 2010 for this running geek:
* National Half Marathon - 03/20 * Frederick Marathon - 05/02 * Baltimore Marathon - 10/16 *
Eric Pascarello
author
Sheriff
Joined: Nov 08, 2001
Messages: 13569
posted Feb 05, 2010 12:20:54
Regular Expression may be easier:
Eric
Race Schedule for 2010 for this running geek:
* National Half Marathon - 03/20 * Frederick Marathon - 05/02 * Baltimore Marathon - 10/16 *
Gina vernon
Ranch Hand
Joined: Jan 16, 2009
Messages: 56
posted Feb 05, 2010 12:30:44
Eric,
Thanks for the reply. I am not sure if reg exps are right for my requirement. The string that I am searching looks like this 'xyz - 34534, y.5'.
I need to fetch the integer between the hyphen and the comma. This integer is of variable length. The only things that remain constant in this string are the hyphen and comma.
Thanks.
Bear Bibeault
Author and opinionated walrus
Sheriff
Joined: Jan 10, 2002
Messages: 36569
posted Feb 05, 2010 12:35:06
That sounds like a textbook case for a regular expression.
[Smart Questions ] [JSP FAQ ] [Books by Bear ] [Bear's FrontMan ] [About Bear ]
Eric Pascarello
author
Sheriff
Joined: Nov 08, 2001
Messages: 13569
posted Feb 05, 2010 13:29:52
Only thing you would need to change is
and
The regular expression will yank it out for you. Test it out!
Eric
Race Schedule for 2010 for this running geek:
* National Half Marathon - 03/20 * Frederick Marathon - 05/02 * Baltimore Marathon - 10/16 *
Gina vernon
Ranch Hand
Joined: Jan 16, 2009
Messages: 56
posted Feb 05, 2010 15:00:28
Eric,
Thanks! I didn't check the thread and I found that this works too:
Eric Pascarello
author
Sheriff
Joined: Nov 08, 2001
Messages: 13569
posted Feb 05, 2010 15:26:07
I would just be careful with the look ahead since IE can be buggy with it. I am not sure if older versions of IE support it.
Eric
Race Schedule for 2010 for this running geek:
* National Half Marathon - 03/20 * Frederick Marathon - 05/02 * Baltimore Marathon - 10/16 *
Gina vernon
Ranch Hand
Joined: Jan 16, 2009
Messages: 56
posted Feb 12, 2010 09:18:03
Thanks!