概念

\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: 

风女郎

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐