js string 转换为十六进制转义序列

 

 

 

function convertToHexEscape(str) {
  let hexEscape = "";
  for (let i = 0; i < str.length; i++) {
    const charCode = str.charCodeAt(i);
    const hexValue = charCode.toString(16);
    hexEscape += "\\x" + hexValue;
  }
  return hexEscape;
}

const input = "los28199";
const hexEscapeSequence = convertToHexEscape(input);
console.log(hexEscapeSequence);

 

posted @ 2023-07-13 00:00  AngDH  阅读(96)  评论(0编辑  收藏  举报