当前位置:网站首页>Unicode string converted to Chinese character decodeunicode utils (tool class II)

Unicode string converted to Chinese character decodeunicode utils (tool class II)

2022-07-07 01:56:00 Novice Zhang~

package com.menglar.soap.item.common.utils;

import org.apache.commons.lang3.StringEscapeUtils;

/** * @description:  take unicode Convert string to Chinese characters  * @author: ZhangRiTian * @create: 2021-10-29 15:08 */
public class DecodeUnicodeUtils {
    

	public static String decodeUnicode(String dataStr) {
    
		// Remove the escape character 
		dataStr = StringEscapeUtils.unescapeJava(dataStr);
		if(!dataStr.contains("\\u")){
    
			return dataStr;}
		int start = 0;
		int end = 0;
		final StringBuffer buffer = new StringBuffer();
		while (start > -1) {
    
			end = dataStr.indexOf("\\u", start + 2);
			String charStr = "";
			if (end == -1) {
    
				charStr = dataStr.substring(start + 2);
			} else {
    
				charStr = dataStr.substring(start + 2, end);
			}
			// 16 Base number parse Shaping string .
			char letter = (char) Integer.parseInt(charStr, 16);
			buffer.append(letter);
			start = end;
		}
		return buffer.toString();
	}
}
原网站

版权声明
本文为[Novice Zhang~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130911190362.html