Trim the file path from the given file name.


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.