How to search word by word in android

后端 未结 5 1872
日久生厌
日久生厌 2021-01-22 08:20

How to search a word in a string?

For example

String text = \"Samsung Galaxy S Two\";

If I use text.contains(\"???\");<

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-22 09:18

    List tokens = new ArrayList();
    
    String text = "Samsung Galaxy S Two";
    StringTokenizer st = new StringTokenizer(text);
    
        //("---- Split by space ------");
        while (st.hasMoreElements()) {
            tokens.add(st.nextElement().toString());
        }
    
        String search = "axy";
        for(int i=0;i Remove Break if you want to continue searching all the words which contains `axy`
            }
        }
    
    output====>Galaxy
    

提交回复
热议问题