This language bar is your friend. Select your favorite languages!

Idiom #133 Case-insensitive string contains

Set boolean ok to true if string word is contained in string s as a substring, even if the case doesn't match, or to false otherwise.

OK := Pos(LowerCase(AWord), LowerCase(S)) > 0;
import std.string;
ok = indexOf(word, s, CaseSensitive.no) != -1;
import "strings"
lowerS, lowerWord := strings.ToLower(s), strings.ToLower(word)
ok := strings.Contains(lowerS, lowerWord)
import Data.Char (toLower)
import Data.List (isInfixOf)
containsIgnoreCase :: String -> String -> Bool
containsIgnoreCase s word = isInfixOf (map toLower word) (map toLower s)
var lowerS = s.toLowerCase();
var lowerWord = word.toLowerCase();
var ok = lowerS.indexOf(lowerWord) !== -1;
ok = word.lower() in s.lower()
ok = s.match?( /#{word}/i )
extern crate regex;
use regex::Regex;
let mut re = String::with_capacity(4 + word.len());
re += "(?i)";
re += word;
let re = Regex::new(&re).unwrap();
ok = re.is_match(&s);

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org

Related idioms