话不多说,直接放代码:
/**
* 获取文件名称前缀
* @param fileName
* @return
*/
public static String getPrefix(String fileName) {
return getPrefix(fileName, false);
}/**
* 获取文件名称前缀
* @param fileName
* @return
*/
public static String getPrefix(String fileName, boolean toLower) {
if (fileName.contains(“.”)) {
String prefix = fileName.substring(0,fileName.lastIndexOf(“.”));
if (toLower) {
return trimilSpace(prefix.toLowerCase());
}
return trimilSpace(prefix);
}
throw new AppException(“文件没有后缀”);
}/**
* @param input
* @return
*/
public static String trimilSpace(String input) {
if (input == null) {
return null;
}
String result = input.replaceAll(“\u00A0”, “”).replaceAll(“\u200B”, “”).replaceAll(“\u2002”, “”)
.replaceAll(“\u200C”, “”).replaceAll(“\u200D”, “”).replaceAll(“\uFEFF”, “”).trim();
if (“”.equals(input)) {
return null;
}
return result;
}