|
This is a function to find ths substring of a string between two strings. this is
same as mid function but here u pass substrings are parameter insted of indexes of substrings
String.prototype.substringBetween = function (string1, string2) {
if ((this.indexOf(string1, 0) == -1) || (this.indexOf(string2, this.indexOf(string1, 0)) == -1)) {
return (-1);
} else {
return this.substring((this.indexOf(string1, 0) + string1.length), (this.indexOf(string2, this.indexOf(string1, 0))));
}
};
var str = "Hello World This is a test";
alert(str.substringBetween("Hello", "This"));
|