SpringBoot 常用工具类----字符串操作工具类StringUtils
1. 简介
字符串操作工具类StringUtils
2. 工具类
2.1. StringUtils
字符串操作工具类
String newStr = " hbhbhhbhbh aaaaaa ";
/*去除尾部的特定字符
String trimTrailingCharacter (String str,char trailingCharacter)*/
String trimTrailingCharacter = StringUtils.trimTrailingCharacter(newStr, 'a');
/*去除头部的特定字符
String trimLeadingCharacter (String str,char leadingCharacter)*/
String trimLeadingCharacter = StringUtils.trimLeadingCharacter(newStr, 'h');
/*去除头部的空白符
String trimLeadingWhitespace (String str)*/
String trimLeadingWhitespace = StringUtils.trimLeadingWhitespace(newStr);
/*去除头部的空白符
String trimTrailingWhitespace (String str)*/
String trimTrailingWhitespace = StringUtils.trimTrailingWhitespace(newStr);
/*去除头部和尾部的空白符
String trimWhitespace (String str)*/
String trimWhitespace = StringUtils.trimWhitespace(newStr);
/*删除开头、结尾和中间的空白符
String trimAllWhitespace (String str)*/
String trimAllWhitespace = StringUtils.trimAllWhitespace(newStr);
/*删除指定子串
String delete (String inString, String pattern)*/
String delete = StringUtils.delete(newStr, "a");
/*删除指定字符(可以是多个)
String deleteAny (String inString, String charsToDelete)*/
String deleteAny = StringUtils.deleteAny(newStr, "ha");
/*对数组的每一项执行 trim() 方法
String[] trimArrayElements (String[]array)*/
String[] trimArrayElements = StringUtils.trimArrayElements(new String[]{"a", "b", "c"});
/*将 URL 字符串进行解码
String uriDecode (String source, Charset charset)*/
String source = "https://www.example.com/?name=John&age=30";
Charset charset = Charset.forName("UTF-8");
String decoded = StringUtils.uriDecode(source, charset);