I am retreiving data from a URL into a String a, and passing this string as an argument to gson's fromJson method. Now I need to replace some of the substrings in string a.
String url = "abc";
String a = getDataFromURL(url); //this string contains all the data from the URL, and getDataFromURL is the method that reads the data from the URL.
String tmp = "\"reservation\":\"www.\"";
String tmpWithHttp = "\"reservation\":\"http://www.\"";
if(a.contains(tmp))
{
a = a.replace(a, tmpWithHttp);
}
All the data in the URL is JSON. The requirement I have here is, if the String a contains a substring - "reservation":"www., replace that with "reservation":"http://www.
The above code I have is not working. Could someone please help me here?
"reservation":"www.", not"reservation":"www.(as your question specifies). That small difference could cause it to not find the replacement string.