字符串长度处理

This commit is contained in:
Chopper 2022-05-18 22:38:13 +08:00
parent d25f17782b
commit b19e4043cd
2 changed files with 15 additions and 5 deletions

View File

@ -147,6 +147,20 @@ public class StringUtils extends StrUtil {
return str.concat(appendStr);
}
/**
* 切割字符串
*
* @param str 字符串
* @param length 长度
* @return 处理后的字符串
*/
public static String sub(String str, Integer length) {
if (str.length() < length) {
return str;
}
return str.substring(0, length);
}
/**
* 过滤特殊字符串
*

View File

@ -49,10 +49,6 @@ public class CashierParam {
if (StringUtils.isEmpty(detail)) {
return "清单详细";
}
//对参数长度进行限制
if (!StringUtils.isEmpty(detail) && detail.length() > MAX_DETAIL_LENGTH) {
detail = detail.substring(30);
}
return StringUtils.filterSpecialChart(detail);
return StringUtils.filterSpecialChart(StringUtils.sub(detail, 30));
}
}