Hello,
I need to check a string to see if it contains another string.
var str1 = "ABCDEFGHIJKLMNOP";
var str2 = "DEFG";
What function do I use to find out if str1 contains str2?
Cheers, Thomas.
Hello,
I need to check a string to see if it contains another string.
var str1 = "ABCDEFGHIJKLMNOP";
var str2 = "DEFG";
What function do I use to find out if str1 contains str2?
Cheers, Thomas.
You can use javascript's indexOf function.
var str1 = "ABCDEFGHIJKLMNOP";
var str2 = "DEFG";
if(str1.indexOf(str2) != -1){
alert(str2 + " found");
}
Check out JavaScript's indexOf function. http://www.w3schools.com/jsref/jsref_IndexOf.asp
In Javascript:
if (str1.indexOf(str2)!=-1) alert('Contains string!');