Logo

Programming-Idioms

  • D
  • Erlang

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.

import std.string;
ok = indexOf(word, s, CaseSensitive.no) != -1;
Re = re:compile(Word, [caseless, unicode]),
Ok = re:run(S, Re) =/= nomatch.
#include <algorithm>
#include <cctype>
auto ok = std::search(std::begin(s), std::end(s), std::begin(word), std::end(word),
    [](auto c, auto d){
        return std::tolower(c) == std::tolower(d);
    }
) != std::end(s);

New implementation...