Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
115
rated 0 times [  121] [ 6]  / answers: 1 / hits: 41723  / 14 Years ago, tue, november 16, 2010, 12:00:00

i want int from string in javascript how i can get them from



test1 , stsfdf233, fdfk323,



are anyone show me the method to get the integer from this string.



it is a rule that int is always in the back of the string.



how i can get the int who was at last in my string


More From » javascript

 Answers
143
var s = 'abc123';
var number = s.match(/d+$/);
number = parseInt(number, 10);


The first step is a simple regular expression - d+$ will match the digits near the end.

On the next step, we use parseInt on the string we've matched before, to get a proper number.


[#94948] Saturday, November 13, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
karivictoriab

Total Points: 530
Total Questions: 90
Total Answers: 95

Location: Honduras
Member since Sun, Dec 26, 2021
2 Years ago
;