com.kuangkie.carbon.util.StringHelper Maven / Gradle / Ivy
package com.kuangkie.carbon.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringHelper {
public static String getFileNameSuffix(String fileName) {
String[] ss=splitFileName(fileName);
if(ss!=null && ss.length==2) {
return ss[1];
}else {
return null;
}
}
public static String[] splitFileName(String fileName){
if(isBlank(fileName)) {
return null;
}
return fileName.split("\\.(?=[^\\.]+$)");
}
public static boolean isNotBlank(String str) {
return !isBlank(str);
}
public static boolean isEmpty( Object str) {
return (str == null || "".equals(str));
}
public static boolean isBlank(String str) {
return str == null || str.trim().length() == 0;
}
public static boolean isBlank(Object obj) {
if(obj==null) {
return true;
}else {
return obj instanceof String ? ((String)obj).trim().length() == 0:false;
}
}
public static boolean longable(String str) {
if(isBlank(str)) {
return false;
}
return str.matches("[0-9]+");
}
public static boolean isNumeric(String pstr) {
if (pstr == null) {
return false;
}
String str = pstr.trim();
if (str.length() == 0) {
return false;
}
String regEx="[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
Pattern p=Pattern.compile(regEx);
Matcher m=p.matcher(str);
if(m.matches()) {
return false;
}
Pattern pattern = Pattern.compile("(-|\\+)?(\\d*)?.?(\\d*)?");
Matcher isNum = pattern.matcher(str);
if (!isNum.matches()) {
return false;
}
return true;
}
}