Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { public static String stripExtension(String inputString) { int lastIndex = inputString.lastIndexOf("."); if (lastIndex < 0) { return inputString; } int fileSeparatorLastIndex = inputString.lastIndexOf(File.separator); if (fileSeparatorLastIndex < 0 && lastIndex == 0) { return inputString; } if (fileSeparatorLastIndex >= 0 && fileSeparatorLastIndex > lastIndex) { return inputString; } return inputString.substring(0, lastIndex); } }