中文与unicode互转

  1. public class MyTest {
  2.     public MyTest(){
  3.         
  4.     }
  5.     
  6.     private String decodeUnicode(final String dataStr ) {
  7.         int start = 0;
  8.         int end = 0;
  9.         final StringBuffer buffer = new StringBuffer();
  10.         while( start > -1 ) {
  11.           end = dataStr.indexOf( "//u", start + 2 );
  12.           String charStr = "";
  13.           if( end == -1 ) {
  14.             charStr = dataStr.substring( start + 2, dataStr.length() );
  15.           } else {
  16.             charStr = dataStr.substring( start + 2, end);
  17.           }
  18.           char letter = (char) Integer.parseInt( charStr, 16 );
  19.           buffer.append( new Character( letter ).toString() );
  20.           start = end;
  21.         }
  22.         return buffer.toString();
  23.     } 
  24.     // /u6240/u6709/u003a/u4e0a/u6d77/u6b27/u4fca/u4fe1/u606f/u6280/u672f/u6709/u9650/u516c/u53f8/u4fdd/u7559/u6240/u6709/u6743
  25.     //所有:上海欧俊信息技术有限公司保留所有权
  26.     // /u51fa/u54c1/u003a/u0020/u4e2d/u56fd/u4e0a/u6d77/u6b27/u4fca/u4fe1/u606f/u6280/u672f/u6709/u9650/u516c/u53f8
  27.     //出品: 中国上海欧俊信息技术有限公司
  28.     public static void main(String args[]){
  29.         MyTest mt=new MyTest();
  30.         String strMesg=mt.decodeUnicode("/u51fa/u54c1/u003a/u0020/u4e2d/u56fd/u4e0a/u6d77/u6b27/u4fca/u4fe1/u606f/u6280/u672f/u6709/u9650/u516c/u53f8");
  31.         System.out.println(strMesg);
  32.     }
  33. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值