android - Check if piece of String is there in string java -
this question has answer here:
i looking piece of code can search string in string.
string mainstr = "it wednesday";
so need code return true if search
"day"
or "day"
or "day"
in mainstr
.
i tried methods like
mainstr.contains("")
and
mainstr.indexof("") > -1
are not working me
thanks :)
if mainstr
long string, approach may more efficient:
string mainstr = "it wednesday"; string tosearch = "day"; boolean found = pattern.compile(tosearch, pattern.case_insensitive).matcher(mainstr).find();
the last line equivalent to
boolean found = pattern.compile("(?i)" + tosearch).matcher(mainstr).find();
but beware tosearch
may not contain regex meta characters if way.
Comments
Post a Comment