I am trying to replace url with another url.
Below is the example of source url
http://sysserver01.internal.com/web/www/internal/projectwork/resources/injury-prevention-and-recovery/avoiding-injury/overview-of-running-injuries/
so this url should be replace with below url,
http://sysserver01.internal.com/var/www/html/injury-prevention-and-recovery/avoiding-injury/overview-of-running-injuries/
It means if source url comes then the part after resources in source url must be appended with /var/www/html/(and rest of part after resources in source url).
This needs to be happen with rendom set of source url that contains resources string.
I dont have enough knowldege of string manipulation. So please someone help me to solve this query. Please try to solve it in JAVA as I choose this platform for my work.
asked Jun 13, 2012 at 17:30
Mahesh
491 gold badge4 silver badges9 bronze badges
-
Did you try String replace method?Subir Kumar Sao– Subir Kumar Sao2012年06月13日 17:34:59 +00:00Commented Jun 13, 2012 at 17:34
-
1"I dont have enough knowldege of string manipulation" See Manipulating Characters in a String. In future please also show more research effort, what you have tried, and make sure to ask a question.Andrew Thompson– Andrew Thompson2012年06月13日 17:35:39 +00:00Commented Jun 13, 2012 at 17:35
2 Answers 2
String originalUrl = "http://sysserver01.internal.com/web/www/internal/projectwork/resources/injury-prevention-and-recovery/avoiding-injury/overview-of-running-injuries";
String newUrl = originalUrl.replaceAll("web/www/internal/projectwork/resources", "var/www/html");
answered Jun 13, 2012 at 17:42
amicngh
7,9293 gold badges37 silver badges55 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
String originalUrl = "http://sysserver01.internal.com/web/www/internal/projectwork/resources/injury-prevention-and-recovery/avoiding-injury/overview-of-running-injuries";
String newUrl = originalUrl.replace("web/www/internal/projectwork/resources", "var/www/html");
answered Jun 13, 2012 at 17:37
Austin Heerwagen
6633 silver badges12 bronze badges
2 Comments
Eric Finn
According to docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html, replace takes two chars, not two Strings.
Eric Finn
@dragon66 Ah, so it does. Java 1.5 String Documentation
lang-java