You can learn more about them here
These can be very usefull, but what if you want the Second indexOf() to get the second occurrence of a specified value in a string. There is no standard JavaScript method for this, so I made my own one;
function SecondIndexOf(Val, Str)
{
var Fst = Str.indexOf(Val);
var Snd = Str.indexOf(Val, Fst+1)
return Snd
}
But why stop there, what if you want the third or fourth indexOf()
The following function lets you specify which occurrence of the specified value to find in the string;
function xIndexOf(Val, Str, x)
{
if (x <= (Str.split(Val).length - 1)) {
Ot = Str.indexOf(Val);
if (x > 1) { for (var i = 1; i < x; i++) { var Ot = Str.indexOf(Val, Ot + 1) } }
return Ot;
} else { alert(Val + " Occurs less than " + x + " times"); return 0 }
}
Here is an egsample of how you can use this;
var PicPath = "/somedirectory/pics/";
var AppPath = picpath.substring(0, xIndexOf('/', PicPath, 2) + 1);
Let me know if you found this usefull, or can recommend any enchancments.


