0

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
2
  • Did you try String replace method? Commented 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. Commented Jun 13, 2012 at 17:35

2 Answers 2

3
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
Sign up to request clarification or add additional context in comments.

Comments

1
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

2 Comments

According to docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html, replace takes two chars, not two Strings.
@dragon66 Ah, so it does. Java 1.5 String Documentation

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.