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

前端 未结 6 1774
一个人的身影
一个人的身影 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:18

    If you are looking to see if a String contains another specific sequence of characters then you could do something like this :

    String stringToTest = "blah blah blah";
    
    if(stringToTest.contains("blah")){
        return true;
    }
    

    You could also use matches. For a decent explanation on matching Strings I would advise you check out the Java Oracle tutorials for Regular Expressions at :

    http://docs.oracle.com/javase/tutorial/essential/regex/index.html

    Cheers,

    Jamie

提交回复
热议问题