feat:新增字符串处理工具类
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
package com.tiesheng.core.util;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class CharacterUtils {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除特殊字符
|
||||||
|
*
|
||||||
|
* @param o 类
|
||||||
|
*/
|
||||||
|
private void removeSymbol(Object o) {
|
||||||
|
removeSymbol(o, "\n|\r|\t| ");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除特殊字符
|
||||||
|
*
|
||||||
|
* @param o 类
|
||||||
|
* @param searchStr 规则
|
||||||
|
*/
|
||||||
|
private void removeSymbol(Object o, String searchStr) {
|
||||||
|
JSONObject object = JSONUtil.parseObj(o, false);
|
||||||
|
for (Map.Entry<String, Object> entry : object) {
|
||||||
|
if (ObjectUtil.isEmpty(entry.getValue()) || StrUtil.equals("null", String.valueOf(entry.getValue()))) {
|
||||||
|
entry.setValue("");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotEmpty(entry.getKey())) {
|
||||||
|
entry.setValue(StrUtil.trim(StrUtil.replace(entry.getValue().toString(), searchStr, "")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BeanUtil.copyProperties(object, o);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user