Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 check the above string to see if it contains just the substring:

"{my string: }"

Many thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
278 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...