Here you can find the source of removeExtension(String s)
Parameter | Description |
---|---|
s | the input path to be stripped |
public static String removeExtension(String s)
//package com.java2s; public class Main { /**// w ww .j ava2s. co m * Removes the path and extension from the input * @param s the input path to be stripped * @return the filename without the path and extension */ public static String removeExtension(String s) { String separator = System.getProperty("file.separator"); String filename; // Remove the path upto the filename. int lastSeparatorIndex = s.lastIndexOf(separator); if (lastSeparatorIndex == -1) { filename = s; } else { filename = s.substring(lastSeparatorIndex + 1); } // Remove the extension. int extensionIndex = filename.lastIndexOf("."); if (extensionIndex == -1) { return filename; } return filename.substring(0, extensionIndex); } }