For loop to search for word in string

后端 未结 4 1241
孤城傲影
孤城傲影 2021-01-18 11:12

I can\'t seem to find the syntax needed for the for loop in this method. I am looking to iterate through the words in the string suit.

EDIT: one thing t

4条回答
  •  盖世英雄少女心
    2021-01-18 11:20

    You could use

    for (String word : suit.split(" ")) {
    

    to split on every space character (U+0020).

    Alternatively:

    for (String word : suit.split("\\s+")) {
    

    This splits on every sequence of whitespace character (this includes tabs, newlines etc).

提交回复
热议问题