android - Check if piece of String is there in string java -


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

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -