la.renzhen.rtpt.admin.util.Strings Maven / Gradle / Ivy
package la.renzhen.rtpt.admin.util;
/**
*
*
* @author haiker
* @version 01/06/2018 5:04 PM
*/
public class Strings {
public static String empty(String a, String b) {
if (a == null || "".equals(a.trim())) {
return b;
}
return a;
}
public static String empty(String a) {
if (a == null) {
return "";
}
return a.trim();
}
/**
* 安全截取操作
*
* @param str 需要截取的字符串
* @param start 截取开始字段
* @param end 截取结束字段
* @return 截取的字符串
*/
public static String sub(String str, int start, int end) {
if (str == null || "".equals(str)) {
return "";
}
int length = str.length();
if (start > length - 1) {
return "";
}
if (end == 0 || end > length) {
end = length - 1;
} else if (end < 0) {
end = length + end;
}
if (start >= end) {
return "";
}
return str.substring(start, end);
}
}