0

指定された文字列から特定の画像パス文字列を抽出したい。

文字列はhttp:\localhost:9090\SpringMVC\images\integration-icon.png

今、次のような画像の後のパスのみを取得したい

\images\integration-icon.png

私はこれを試しました

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

どうすれば入手することができますか ?

4

6 に答える 6

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

または(試しておらず、やや奇妙に見えます)

String filename = filepath.substring(filepath.lastIndexOf("\\", "images\\".length()) + 1);
于 2013-10-18T11:07:59.633 に答える
0
String string = "http:\localhost:9090\ZenoBusinessStore\images\integration-icon.png";
int index = string.indexOf("images\\");
String output = string.substring(index);
于 2013-10-18T11:08:02.963 に答える
0
String text = "http:\localhost:9090\SpringMVC\images\integration-icon.png"
String subText = text.subString(text.indexOf("\images"), text.length());
System.out.println(subText);
于 2013-10-18T11:09:23.703 に答える
0
String in = "http:\\localhost:9090\\ZenoBusinessStore\\images\\integration-icon.png";
String op = in.replace("http:\\localhost:9090\\ZenoBusinessStore", "");
System.out.println(op);
于 2013-10-18T11:10:20.397 に答える
0

ZenoBusinessStore定数であるプロジェクトの名前でなければなりません。今すぐ文字列を分割します

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

これで、配列の 2 番目の要素がイメージ パスになります。

 System.out.println(ary[1]);
于 2013-10-18T11:10:51.070 に答える