views:

36

answers:

2
'123xswer'

How to retrieve 123 from the string above without using regular expression?

A: 

Use split function .

var str='123xwer' ;
arr = str.split('x') ;
alert ( arr[0] ) ;
pavun_cool
you assume too much.
mkoryak
+3  A: 
> parseInt('123xswer', 10)
  123

(Leading zeros won't be kept.)

(The "10" is to specify we want decimal numbers, so that 099abcd can return the expected integer.)

KennyTM