Answers for "string contains substring"

SQL
2

angular string contains

var string = "foo";
var substring = "oo";

console.log(string.indexOf(substring) !== -1);
Posted by: Guest on March-24-2020
1

check if string contains substring

Like this:

if (str.indexOf("Yes") >= 0)
...or you can use the tilde operator:

if (~str.indexOf("Yes"))
This works because indexOf() returns -1 if the string wasn't found at all.

Note that this is case-sensitive.
If you want a case-insensitive search, you can write

if (str.toLowerCase().indexOf("yes") >= 0)
Or:

if (/yes/i.test(str))
Posted by: Guest on March-04-2021

Code answers related to "string contains substring"

Code answers related to "SQL"

Browse Popular Code Answers by Language