Reputation: 111
I have a class called GamesData that has strings and getters and setters for this strings.
I download strings from a json. One of these strings is an URL with an image. I download the images but on a small size, because of their URL. I need to download it on a bigger size. For this, I need to remove this "small" string from the URL:
"home_team_logo": "https:\/\/URL\/images\/teams\/small\/olympique-marseille-890.png"
I have more than one URL coming from a big json object, all inside a json array, formated like the one above.
This is what I do to get the json.
arrayList.add(new GamesData(
gamesDataObject.getString(TAG_DATE),
gamesDataObject.getString(TAG_COMPETITION),
gamesDataObject.getString(TAG_HOME_TEAM),
gamesDataObject.getString(TAG_AWAY_TEAM),
gamesDataObject.getString(TAG_ID)
));
I need to remove from TAG_HOME_TEAM
public static final String TAG_HOME_TEAM= "home_team_logo";
, which is that URL above, only the "small" part, so the image downloaded will be the full size one.
In fact I will need this for all 3 tags: TAG_COMPETITION, TAG_HOME_TEAM, TAG_AWAY_TEAM.
How on earth do I do this? xD
Upvotes: 1
Views: 502
Reputation: 11248
I'm thinking something like this might work:
gamesDataObject.getString(TAG_HOME_TEAM).replaceAll("\/small\/","/");
This uses a regular expression to match all occurrences of the patern. A simplepr less error prone approach may be to use
gamesDataObject.getString(TAG_HOME_TEAM).replace("\/small\/","/");
Which should only replace the first occurrence.
Upvotes: 1
Reputation: 37404
You can use replace
, use /small/
with /
as replacement to avoid matching something like /othersmallteamname/
String s = "https:/URL/images/teams/small/olympique-marseille-890.png";
System.out.println(s.replace("/small/", "/"));
Output :
https:/URL/images/teams/olympique-marseille-890.png
Upvotes: 2