How do I check if string contains substring? [duplicate]

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)) The latter is a regular expression … Read more

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

Now with PHP 8 you can do this using str_contains: if (str_contains(‘How are you’, ‘are’)) { echo ‘true’; } RFC Before PHP 8 You can use the strpos() function which is used to find the occurrence of one string inside another one: $a=”How are you?”; if (strpos($a, ‘are’) !== false) { echo ‘true’; } Note … Read more

Case insensitive ‘Contains(string)’

You could use the String.IndexOf Method and pass StringComparison.OrdinalIgnoreCase as the type of search to use: string title = “STRING”; bool contains = title.IndexOf(“string”, StringComparison.OrdinalIgnoreCase) >= 0; Even better is defining a new extension method for string: public static class StringExtensions { public static bool Contains(this string source, string toCheck, StringComparison comp) { return source?.IndexOf(toCheck, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)