문제

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.

도움이 되었습니까?

해결책

origStr.replaceFirst("/[^/]+/", "");

should work

다른 팁

You can do something like this -

    String str = "/unwanted/wanted1/wanted2/and_so_on";
    String temp = str.substring(str.indexOf("/", 1)+1);
    System.out.println(temp);

Without using regEx.You can use split("/") method to make it into String array.And cutting down the first element.

String [] arr= origSTr.split("/");

Use this arr as you wish.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top