1

I have a string

String origStr = "/unwanted/wanted1/wanted2/and_so_on"

i want to make this as

String finalStr = "wanted1/wanted2/and_so_on"

I thought of doing that using regEx in Java. But struck on this.

4

4 回答 4

6

你可以做这样的事情 -

    String str = "/unwanted/wanted1/wanted2/and_so_on";
    String temp = str.substring(str.indexOf("/", 1)+1);
    System.out.println(temp);
于 2012-06-12T05:53:13.390 回答
5
origStr.replaceFirst("/[^/]+/", "");

应该管用

于 2012-06-12T05:53:23.900 回答
0

不使用正则表达式。您可以使用split("/")方法将其制成字符串数组。并削减第一个元素。

于 2012-06-12T05:54:02.013 回答
0
String [] arr= origSTr.split("/");

根据需要使用此 arr。

于 2012-06-12T05:55:29.710 回答