سؤال

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