-3

I am able to capture a file name in either a File or String format. For example the file paths.

\EAM\testing
\EAM\development
\System\Applications\Management

I need to break these into different strings or substring so they would be

\EAM\testing
String 1: EAM
String 2: testing

\EAM\development
String 1: EAM
String 2: development

\System\Applications\Management
String 1: System
String 2: Applications
String 3: Management

For the first two I know i could possibly use

int index = myStr.lastIndexOf('@');
String firstPart = myStr.substring(1, index);

Any help is greatly appreciated.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373

2 Answers2

0
String[] parts = myStr.split("\\");
Dave Morrissey
  • 4,371
  • 1
  • 23
  • 31
0

Use String.split() method to get all the values in an array:

String []names = filePathString.split("\\");
for(String name:names) {
   System.out.println("name: " + name);
}
Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136