0

I have a String name packageName="https://play.google.com/store/apps/details?id=com.MoversGames.DinosaurWorldGame"; How i can get subString from this string. I want to take "id=com.MoversGames.DinosaurWorldGame" this from String packgeName. The length of this String may change. It is not constant its variable .

4
  • you can do it using regex Commented Oct 11, 2018 at 10:50
  • @NawnitSen Regex? You could also do it with a 3rd party webserver, but why would you need so powerful for something so simple. Commented Oct 11, 2018 at 10:51
  • 1
    Just split the String with the delimiter ? and you will get your result. Commented Oct 11, 2018 at 10:53
  • @NickCardoso that is the first thing that came to my mind. Commented Oct 11, 2018 at 10:53

2 Answers 2

2

You need to use String.substring()

Try to substring your string from the index of id to length of your string

In this below example i have started substring from index of ? +1 so it will start substring your string from id to length of your string

SAMPLE CODE

    String packageName = "https://play.google.com/store/apps/details?id=com.MoversGames.DinosaurWorldGame";

    String answer = packageName.substring(packageName.indexOf("?")+1, packageName.length() );
    Log.e("ANSWER", answer);

OUTPUT

2018-10-11neel.com.myapplication E/ANSWER: id=com.MoversGames.DinosaurWorldGame
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you bro..you saved my time which was too critical!
0

There might be also some more query parameters in your String , so you can also try it like this :

String packageName = "https://play.google.com/store/apps/details?i 
id=com.MoversGames.DinosaurWorldGame&x=y&z=a";

String answer = packageName.substring(packageName.indexOf("id"));
System.out.print("ANSWER", answer);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.