js 里 \x 开头的通常是16进制编码的数据,下面代码实现编解码:

解码

function decode(str){
	return str.replace(/\\x(\w{2})/g,function(_,$1){ return String.fromCharCode(parseInt($1,16)) });
}

eg.

decode('\x5f\x63\x68\x61\x6e\x67\x65\x49\x74\x65\x6d\x43\x72\x6f\x73\x73\x4c\x61\x79\x65\x72')

"_changeItemCrossLayer"

编码

function encode(str){
    return str.replace(/(\w)/g,function(_,$1){ return "\\x"+ $1.charCodeAt(0).toString(16) });
}

eg.

encode("_changeItemCrossLayer")

"\x5f\x63\x68\x61\x6e\x67\x65\x49\x74\x65\x6d\x43\x72\x6f\x73\x73\x4c\x61\x79\x65\x72"

延伸:

python将\x 开头编码的数据解码成中文

相关文章:

  • 2022-12-23
  • 2021-12-04
  • 2021-06-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-24
猜你喜欢
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
  • 2021-05-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案