View Single Post
Old 12-13-2012, 07:41 AM   PM User | #14
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,032
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by 123jo View Post
Anyone has an idea of how I can get the last integer of a string? Parsing doesn't seem to work...

<script type = "text/javascript">

Code:
var str = "1234a56d";
str = str.replace(/[^\d]/gi,"");
var len = str.length;
var x = str.charAt(len-1);
alert (x);


var str = "14x10+2x1123";
var x = str.match(/\d+\D*/gi);
var len = x.length;
var y = Number(x[len-1].replace(/[^\d]/g,""));
alert (y);

</script>
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 12-13-2012 at 08:05 AM..
Philip M is offline   Reply With Quote