码迷,mamicode.com
首页 > 其他好文 > 详细

16进制的字符串转化为utf-8格式的字符串

时间:2019-01-30 14:22:15      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:byte   string   not   ++   tostring   进制   substr   16进制   turn   

    /**
     * 16进制的字符串转化为utf-8格式的字符串
     * @param s
     * @return
     */
    public static String toStringHex(String s) {
        byte[] baKeyword = new byte[s.length() / 2];
        for (int i = 0; i < baKeyword.length; i++) {
        try {
        baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(
        i * 2, i * 2 + 2), 16));
        } catch (Exception e) {
        e.printStackTrace();
        }
        }
        try {
        s = new String(baKeyword, "utf-8");// UTF-16le:Not
        } catch (Exception e1) {
        e1.printStackTrace();
        }
        return s;
    }

 

16进制的字符串转化为utf-8格式的字符串

标签:byte   string   not   ++   tostring   进制   substr   16进制   turn   

原文地址:https://www.cnblogs.com/huyanlon/p/10337636.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!