- public class MyTest {
- public MyTest(){
- }
- private String decodeUnicode(final String 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, dataStr.length() );
- } else {
- charStr = dataStr.substring( start + 2, end);
- }
- char letter = (char) Integer.parseInt( charStr, 16 );
- buffer.append( new Character( letter ).toString() );
- start = end;
- }
- return buffer.toString();
- }
- // \u6240\u6709\u003a\u4e0a\u6d77\u6b27\u4fca\u4fe1\u606f\u6280\u672f\u6709\u9650\u516c\u53f8\u4fdd\u7559\u6240\u6709\u6743
- //所有:上海欧俊信息技术有限公司保留所有权
- // \u51fa\u54c1\u003a\u0020\u4e2d\u56fd\u4e0a\u6d77\u6b27\u4fca\u4fe1\u606f\u6280\u672f\u6709\u9650\u516c\u53f8
- //出品: 中国上海欧俊信息技术有限公司
- public static void main(String args[]){
- MyTest mt=new MyTest();
- String strMesg=mt.decodeUnicode("\u51fa\u54c1\u003a\u0020\u4e2d\u56fd\u4e0a\u6d77\u6b27\u4fca\u4fe1\u606f\u6280\u672f\u6709\u9650\u516c\u53f8");
- System.out.println(strMesg);
- }
- }
中文与unicode互转
最新推荐文章于 2022-10-13 19:22:57 发布
本文提供了一个Java方法用于将Unicode转义序列转换为对应的字符。通过解析输入字符串中的每个Unicode序列并将其转换成实际字符来实现这一过程。示例展示了如何使用该方法解码一条包含中文的版权信息。
1298

被折叠的 条评论
为什么被折叠?



