I need to parse a file path to get the filename from it. What confuses me is that windows uses \ as the delimeter and linux - / and somehow the provided filepath can even contain both delimeters at the same time.
Of course I can do:
int slash = filePath.lastIndexOf("/");
int backslash = filePath.lastIndexOf("\\");
fileName = filePath.substring(slash > backslash ? slash : backslash);
but is there a better way in case I have more delimiters? (probably not for a file path)
File f = new File(fileName); String name = f.getName();