开箱即用,无副作用
/**
* 字符串工具类
* @description TODO
* @date 2020/7/24-17:16
*/
public class StringUtils {
/**
* 去除字符串中的特殊字符
*
* @param oldchinese 含有特殊字符的字符串
* @return
*/
private static String removeSpecialStr(String str) {
//正则表达式
String regEx = "[\n`~!@#$%^&*()+=\\-|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。, 、?]";
//特殊字符替换,”“表示去除
String aa = "";
return str.replaceAll(regEx, aa);
}
/**
* 去除字符串首尾出现的某个字符.
*
* @param source 源字符串.
* @param element 需要去除的字符.
* @return String.
*/
public static String trimFirstAndLastChar(String source, char element) {
boolean beginIndexFlag ;
boolean endIndexFlag ;
do {
int beginIndex = source.indexOf(element) == 0 ? 1 : 0;
int endIndex = source.lastIndexOf(element) + 1 == source.length() ? source.lastIndexOf(element) : source.length();
source = source.substring(beginIndex, endIndex);
beginIndexFlag = (source.indexOf(element) == 0);
endIndexFlag = (source.lastIndexOf(element) + 1 == source.length());
} while (beginIndexFlag || endIndexFlag);
return source;
}
/**
* 正则判断是否存在一到十的罗马字符
*
* @param romaStr 需要判断的字符串
* @return
*/
public static Boolean isRomaStr(char romaStr) {
String regEx = "[ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(String.valueOf(romaStr));
return m.find();
}
}