I have a String which is a website URL, such as "http://www.abcd.com/en/sites/default/files/pic.jpg". I want to split this String so that I can change some of the path values, such as changing /files/ to /newfolder/.
Is this easily achievable?
This will remove the part after the last "/" and append "newfolder/pic.jpg"
String str = "http://www.abcd.com/en/sites/default/files/pic.jpg";
str.substring(0, s.lastIndexOf("/") + 1) + "newfolder/pic.jpg";
str.substring(0, s.lastIndexOf("/") + 1) + "newfolder" + substring(s.lastIndexOf("/"));)Use a replace function and replace "files/" by "files/newfolder/", for example.
http://www.abcd.com/en/sites/files/default/files/pic.jpgString string = "http://www.abcd.com/en/sites/default/files/pic.jpg";
string.replace("files/", "files/newfolder/");