Forum Moderators: open

Message Too Old, No Replies

string to integer function in ie

         

Jesse

9:00 am on Dec 21, 2008 (gmt 0)

10+ Year Member



Hello all,

I have the following code for returning either the first or the last integer within a string:

String.prototype.lastInt=function(){
var a=this.match(/\d+/g);
var b=a.pop();
b-=0;
return b;
}

String.prototype.firstInt=function(){
var a=this.match(/\d+/g);
var b=a[0];
b-=0; //error on this line
return b;
}

which works in firefox but doesn't work in ie. Ie throws the following error: " '0' is null or not an object " on the marked line.

Why is this? Howcome ie thinks I am attempting to use b as an object?

Sephr

12:58 am on Dec 22, 2008 (gmt 0)

10+ Year Member



try parseInt(b, 10) instead of b-=0