+ 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?
6 Antworten
+ 7
kev_coding
You can do like this:
https://code.sololearn.com/cFeiXaNAx8EB/?ref=app
+ 4
Try using .toLowerCase() method
if(line.contains(word.toLowerCase()))
+ 4
kev_coding
Convert both string to lower case then check contains
Or using regex you can check.
+ 4
Thank you all.
+ 3
// try
if (line.toLowerCase().contains(word.toLowerCase())) {
https://code.sololearn.com/cta4iV6H99Dp
0
A͢J okay. But where ? in which line?