0

I want to extract a perticular image path string from a given string .

The String is http:\localhost:9090\SpringMVC\images\integration-icon.png

Now i want to get only the path after images like

\images\integration-icon.png

i tried this

Pattern pattern = Pattern.compile("SpringMVC");
Matcher matcher = pattern.matcher(str);
System.out.println("Checking");
if (matcher.find()) {
    System.out.println(matcher.group(1));
}

how can i get ?

3

6 Answers 6

2
String filename = filepath.substring(filepath.lastIndexOf("\\") + 1);

or (haven't tried and looks somewhat odd)

String filename = filepath.substring(filepath.lastIndexOf("\\", "images\\".length()) + 1);
Sign up to request clarification or add additional context in comments.

Comments

0
String string = "http:\localhost:9090\ZenoBusinessStore\images\integration-icon.png";
int index = string.indexOf("images\\");
String output = string.substring(index);

3 Comments

wont work, you'll get the error - Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ ). Use escape sequences.
Are you sure? because I used a valid one
try and run it on a compiler.
0
String text = "http:\localhost:9090\SpringMVC\images\integration-icon.png"
String subText = text.subString(text.indexOf("\images"), text.length());
System.out.println(subText);

Comments

0
String in = "http:\\localhost:9090\\ZenoBusinessStore\\images\\integration-icon.png";
String op = in.replace("http:\\localhost:9090\\ZenoBusinessStore", "");
System.out.println(op);

Comments

0

ZenoBusinessStore must be the name of your project which is constant. Now split the string

String s = "http:\localhost:9090\ZenoBusinessStore\images\integration-icon.png";
String ary = s.split("ZenoBusinessStore");

Now the 2nd element of the array is your image path.

 System.out.println(ary[1]);

1 Comment

wont work, you'll get the error - Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ ). Use escape sequences.
0

Use '\\'. It's because backslash is used in escape sequence like '\n'. With a single \ the compiler have no way to know.

Comments

Your Answer

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.