Posted By

walokra on 04/08/09


Tagged

java files strings


Versions (?)

Trim the file path from the given file name.


 / Published in: Java
 

  1. /**
  2.  * Trim the file path from the given file name. Anything before the last occurred "/" and "\" will be
  3.  * trimmed, including the slash.
  4.  *
  5.  * @param fileName
  6.  * The file name to trim the file path from.
  7.  * @return The file name with the file path trimmed.
  8.  */
  9. public static String trimFilePath(String fileName) {
  10. return fileName.substring(fileName.lastIndexOf("/") + 1).substring(fileName.lastIndexOf("\\") + 1);
  11. }

Report this snippet  

You need to login to post a comment.