Answers for "find if a string has another string"

PHP
2

How do I check if a string contains a specific word?

$a = 'Hello world?';

if (strpos($a, 'Hello') !== false) { //PAY ATTENTION TO !==, not !=
    echo 'true';
}
if (stripos($a, 'HELLO') !== false) { //Case insensitive
    echo 'true';
}
Posted by: Guest on May-18-2020
0

check if string is substring of another string

function mutation(arr) {
  let first = arr[0];
  let second = arr[1];
  
  return first.indexOf(second) !== -1;
}

console.log(mutation(["hello", "hel"]));
Posted by: Guest on September-04-2021

Code answers related to "find if a string has another string"

Browse Popular Code Answers by Language