+2 votes
885 views
in Programming by (720 points)
edited by
Hi All, I have a Big String which is dynamic and want get some spacific characters from that String.
 
Like I have a String strMain = "My country name is India"
 

here I want to check what is the country name . Because this string is dynamic, I mean some time the string becomes

New country is USA

and some time My country is Poland. It comes with different-2 sentence . so its difficult for me to compare country name with another string. so please suggest any logic for the same.

 

Thanks For helping me.

 

2 Answers

+1 vote
by
Please look into classes like Pattern and Matcher.

Here the idea is to device the string as regex like :

My country name is (\S+) and user matcher to capture matching group.
0 votes
by (2.6k points)
edited by

You can use java.lang.String.contains() method .

You have string strMain so you can check secuence of substrings and can compare those sub strings with your dynamic result like 
 

String strCountry = "India";

boolean  Finalstr = strMain.contains("+strCountry+");

Because this method return true or false so by Finalstr you can varify dynamic string contains that India or same as other countries  or not.

I hope it would help you.

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated