javascript| case
Look at me, it's compatible with the original indexOf.
<script language=javascript>
/*
Author: Niu (New Kunliang) qq:273352165 msn:niukl@hotmail.com
Disclaimer: You can use it for free, please keep this information
If you have anything to mend, please tell me!
*/
String.prototype._indexof = String.prototype.indexOf;
String.prototype.indexOf = function ()
{
if (typeof (Arguments[arguments.length-1])!= ' Boolean ')
Return this._indexof.apply (this,arguments);
Else
{
var bi = arguments[arguments.length-1];
var thisobj = this;
var idx = 0;
if (typeof (Arguments[arguments.length-2]) = = ' number ')
{
IDX = arguments[arguments.length-2];
Thisobj = this.substr (idx);
}
var re = new RegExp (arguments[0],bi? ') I ': ');
var r = Thisobj.match (re);
return r==null?-1:r.index + idx;
}
}
Alert ("Bcssssasdfsdf". IndexOf (' A ', 3,true));
Alert ("Bcssssasdfsdf". IndexOf (' A ', 3));
</script>
The following is the program code <script language=javascript>
/*
Author: Niu (New Kunliang) qq:273352165 msn:niukl@hotmail.com
Disclaimer: You can use it for free, please keep this information
If you have anything to mend, please tell me!
*/
String.prototype._indexof = String.prototype.indexOf;
String.prototype.indexOf = function ()
{
if (typeof (Arguments[arguments.length-1])!= ' Boolean ')
Return this._indexof.apply (this,arguments);
Else
{
var bi = arguments[arguments.length-1];
var thisobj = this;
var idx = 0;
if (typeof (Arguments[arguments.length-2]) = = ' number ')
{
IDX = arguments[arguments.length-2];
Thisobj = this.substr (idx);
}
var re = new RegExp (arguments[0],bi? ') I ': ');
var r = Thisobj.match (re);
return r==null?-1:r.index + idx;
}
}
Alert ("Bcssssasdfsdf". IndexOf (' A ', 3,true));
Alert ("Bcssssasdfsdf". IndexOf (' A ', 3));
</script>
2005-11-7 16:20 Chrothra
The following is the program code
<script>
String.prototype.indexOf = function (f,s,m) {
if (f = = null) {return;}
var st = (s!= null && typeof (s) = = "Number" && s < this.length)? parseint (s): 0;
var mm = (M = = False)? "I": "";
var re = eval ("/" + f.tostring () + "/" +mm);
var ss = (St = = 0)? This:this.substr (ST);
var RT = Ss.match (re);
return (RT = null)? -1:rt.index + st;
}
</script>