StringUtil.java
1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package cn.com.glsx.scrm.equity.util;
import org.apache.commons.lang.StringUtils;
import org.oreframework.util.lang.EmojiUtil;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
/**
* @author pengfang
* @description
* @date Created in 16:22 2021/8/27
*/
public class StringUtil {
/**
* 解码昵称
* @param name
* @return
* @author Alvin.zengqi
* @date 2018年4月17日 下午4:30:07
*/
public static String decode(String name){
if(org.apache.commons.lang.StringUtils.isNotEmpty(name)){
try {
return URLDecoder.decode(name, "utf-8");
} catch (UnsupportedEncodingException e) {
}
}
return name;
}
/**
* 转码昵称
* @param name
* @return
* @author Alvin.zengqi
* @date 2018年4月17日 下午4:30:07
*/
public static String encode(String name){
if(StringUtils.isNotEmpty(name)){
try {
return URLEncoder.encode(name, "utf-8");
} catch (UnsupportedEncodingException e) {
return EmojiUtil.filterEmoji(decodeCharset(name));
}
}
return name;
}
/**
* 转码字符串
* @param
* @return java.lang.String
* @author pengfang
* @date 2021/9/13 18:14
*/
public static String decodeCharset(String source) {
try {
if (StringUtils.isNotEmpty(source)) {
return new String(source.getBytes("iso8859-1"), "UTF-8");
}
return source;
}
catch (Exception e) {
return source;
}
}
}