| Author |
parseInt method
|
Gina vernon
Ranch Hand
Joined: Jan 16, 2009
Posts: 108
|
|
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
Rancher
Joined: Nov 08, 2001
Posts: 14858
|
|
indexOf returns a number, so why are you using parseInt to start with?
Eric
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 14858
|
|
Regular Expression may be easier:
Eric
|
 |
Gina vernon
Ranch Hand
Joined: Jan 16, 2009
Posts: 108
|
|
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
Marshal
Joined: Jan 10, 2002
Posts: 48842
|
|
|
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
Rancher
Joined: Nov 08, 2001
Posts: 14858
|
|
Only thing you would need to change is
and
The regular expression will yank it out for you. Test it out!
Eric
|
 |
Gina vernon
Ranch Hand
Joined: Jan 16, 2009
Posts: 108
|
|
Eric,
Thanks! I didn't check the thread and I found that this works too:
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 14858
|
|
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
|
 |
Gina vernon
Ranch Hand
Joined: Jan 16, 2009
Posts: 108
|
|
|
Thanks!
|
 |
 |
|
|
subject: parseInt method
|
|
|