To check if string contains particular word

后端 未结 10 731
野的像风
野的像风 2020-12-08 04:55

So how do you check if a string has a particular word in it?

So this is my code:

a.setOnClickListener(new View.OnClickListener() {

        @Overri         


        
10条回答
  •  醉酒成梦
    2020-12-08 05:14

       String sentence = "Check this answer and you can find the keyword with this code";
        String search = "keyword";
    

    Compare the line of string in given string

    if ((sentence.toLowerCase().trim()).equals(search.toLowerCase().trim())) {
    System.out.println("not found");
    }
    else {  
        System.out.println("I found the keyword"); 
    } 
    

提交回复
热议问题