\X开头的编码转为汉字的几种方式

概念

\x开头的编码是十六进制字符,\x后面跟的字符即为十六进制的字符串。

解码方式

将\x转为中文的几种方式:

1 在linux客户端通过命令echo -e 输出

[root@localhost ~]# echo -e '\xe9\xa3\x8e\xe5\xa5\xb3\xe9\x83\x8e'
风女郎

2 将<\x>替换为%,使用UrlDecoder工具进行解码

  •  转\x为%得到
\xe9\xa3\x8e\xe5\xa5\xb3\xe9\x83\x8e

%e9%a3%8e%e5%a5%b3%e9%83%8e

3 JAVA解码

package com.tjh.encryption.utils.encodedecode;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

/**
 * @auth tangjianghua
 * @date 2021/2/24
 */
public class Hex2Str {


    public static String hex2UTF8(String hexStr) throws UnsupportedEncodingException {
        return URLDecoder.decode(hexStr.replaceAll("\\\\x", "%"), StandardCharsets.UTF_8.name());
    }

    public static String hex2GBK(String hexStr) throws UnsupportedEncodingException {
        return URLDecoder.decode(hexStr.replaceAll("\\\\x", "%"), "gbk");
    }

    public static void main(String[] args) throws Exception{
        String utf8String = "\\xe9\\xa3\\x8e\\xe5\\xa5\\xb3\\xe9\\x83\\x8e";
        System.out.println(hex2UTF8(utf8String));
    }
}

console: 

风女郎

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值