How to check if a string contains a substring containing spaces?

前端 未结 6 1777
一个人的身影
一个人的身影 2020-12-18 12:26

Say I have a string like this in java:

\"this is {my string: } ok\"

Note, there can be any number of white spaces in between the various characters. How do I

6条回答
  •  粉色の甜心
    2020-12-18 13:05

    The easiest thing to do is to strip all the spaces from both strings.

    return stringToSearch.replaceAll("\s", "").contains(
      stringToFind.replaceAll("\s", ""));
    

提交回复
热议问题