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 .
2 Answers
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
1 Comment
BharathRao
Thank you bro..you saved my time which was too critical!
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);
?and you will get your result.