简体   繁体   中英

Ignoring capital letters when checking if a string contains a word

I don't know, but for the life of me I can't seem to figure out/find out how to make it so when i'm checking to see if a string contains a certain word, it ignores the capital letters within the word.

Thanks in advanced! ~Sean

You can convert the comparing string to lowercase.

String s = "ABC";
if (s.toLowerCase().contains("abc")); //returns true

But if it were me..

s.equalsIgnoreCase("abc");

can be used if you're comparing the entire String. Which is fine.

But in general, Google these types of questions first. There are millions of answers for this exact question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM