This is a simple function in JavaScript, I use it to check if a string contains another string.The different in this function is that the return value is the position+1.So you could use it in an If without to check the return value manually, just see my test from 1 to 3.
This is the function:
1 2 3 |
function string_contains(str,needle) { return(str.indexOf(needle)+1); } |
Now we make a little test to see if it work:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
//Test 1 if(string_contains("abcdef","a")){ console.log("abcdef contains a"); }else{ console.log("abcdef not contains a"); } //Test 2 if(string_contains("abcdef","b")){ console.log("abcdef contains b"); }else{ console.log("abcdef not contains b"); } //Test 3 if(string_contains("abcdef","z")){ console.log("abcdef contains z"); }else{ console.log("abcdef not contains z"); } |
Seems good:
1 2 3 |
abcdef contains a abcdef contains b abcdef not contains z |
whoah this weblog is magnificent i really like reading your
articles. Stay up the good work! You already know,
lots of persons are searching round for this information, you could aid them greatly.
I was able to find good information from your content.
Wow, this post is fastidious, my sister is analyzing these
kinds of things, therefore I am going to inform her.