Commit 6d114a5a authored by 杨林's avatar 杨林

解析unicode工具

parent c55b0d08
package tools.unicode
import java.util.regex.Pattern
/**
* @ClassName: qm.qiaomeng.jackson
* @Description:
* @Author:LinYoung
* @Date: 2021/3/26
* @Time: 13:09
*/
object UnicodeUtils {
/**
* 解码
* @param str 要解码的字符串
* @return 解码后的字符串
*/
def decode(str: String): String = {
val pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))")
val matcher = pattern.matcher(str)
var unicode = str
while (matcher.find()) {
val ch: Char = Integer.parseInt(matcher.group(2), 16).asInstanceOf[Char]
unicode = unicode.replace(matcher.group(1), ch + "")
}
unicode
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment