Contains string matching algorithm