0

i have a requirement i needed to be figure out .

consider a string for ex "/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX/XXXXXXX ......n times "

I needed to get the second set of string from this string,last string set,with out last string set rest of the String. xx mentioned in example can be a-z,A-z,0-9,and spaces also. i am able to get last string set,with out last string set rest of the String. please let me know how to get 2nd string set.

              String a ="/WorkGroups/Testing Test WG 1/R14A";
              int position = a.lastIndexOf('/');
              System.out.println(position);//Print 28 
              System.out.println(a.substring(0,position));//print /WorkGroups/EriDoc Test WG 1
              System.out.println(a.substring(position+1));//print R14A

how to get only Testing Test WG 1 ?

1
  • a little bit more clarification please Commented Jul 17, 2014 at 11:22

3 Answers 3

1
String[] arr = yourString.split("/");
arr[whateverIndexYouWant]
Sign up to request clarification or add additional context in comments.

Comments

0

Here is the code -

    String a ="/WorkGroups/Testing Test WG 1/R14A";
    System.out.println(a.split("/")[2]);

Output -

 Testing Test WG 1

Comments

0

This is an option :

System.out.println(a.substring(12, 28)

First parameter is an index of a start element, second parameter is an index of last element.

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.