jQuery in Action
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of Flex 4 in Action this week in the Flex forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Engineering » HTML and JavaScript
 
RSS feed
 
New topic
Author

parseInt method

Gina vernon
Ranch Hand

Joined: Jan 16, 2009
Messages: 56

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

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

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

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

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

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

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

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

Thanks!
 
jQuery in Action
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Engineering » HTML and JavaScript
 
RSS feed
 
New topic
replay challenge