简体   繁体   English

从JavaScript中的字符串中删除基于十六进制值的特定字符

[英]Remove specific character based on Hex value from string in JavaScript

Now, I want to remove all extra \\x characters before hex value, and keep the hex value as string. 现在,我想删除十六进制值之前的所有多余\\x字符,并将十六进制值保留为字符串。 For example, 例如,

Convert the string 转换字符串

"\\\\x1D\\\\x06\\\\x1BH\\\\x18+Congratulations!\\\\x1D\\\\x00"

to the content of new string 到新字符串的内容

1d 06 1b 48 18 2b 43 6f 6e 67 72 61 74 75 6c 61 74 69 6f 6e 73 21 1d 00

How to do it in JavaScript efficiently? 如何在JavaScript中有效地做到这一点?

It seems works well with the following codes 使用以下代码似乎效果很好

var ss = "\\x1D\\x06\\x1BH\\x18+Congratulations!\\x1D\\x00";

ss.replace(/\\x[0-9a-fA-F]{2}/g, function(v){ 
   return String.fromCharCode(parseInt(v.substr(2), 16));
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM