+ 2

Question

Read a line of text and reject it if it contains a prohibited word. It should be case insensitive. I wrote this: { String word = "Hate"; String line = "we hate us and we hate you." If(line.contains(word)){ Sout("not ok"); Else{ Sout("ok") } But what should I do make it case insensitive?

5th Mar 2022, 11:31 AM
kev_coding
kev_coding - avatar
6 odpowiedzi
5th Mar 2022, 12:07 PM
A͢J
A͢J - avatar
+ 4
Try using .toLowerCase() method if(line.contains(word.toLowerCase()))
5th Mar 2022, 11:56 AM
Simba
Simba - avatar
+ 4
kev_coding Convert both string to lower case then check contains Or using regex you can check.
5th Mar 2022, 11:56 AM
A͢J
A͢J - avatar
+ 4
Thank you all.
5th Mar 2022, 12:16 PM
kev_coding
kev_coding - avatar
+ 3
// try if (line.toLowerCase().contains(word.toLowerCase())) { https://code.sololearn.com/cta4iV6H99Dp
5th Mar 2022, 12:12 PM
SoloProg
SoloProg - avatar
0
A͢J okay. But where ? in which line?
5th Mar 2022, 11:55 AM
kev_coding
kev_coding - avatar