简体   繁体   English

如何将ASCII码字符串转换为字符串?

[英]How to convert string of ASCII codes to string of characters?

Need to convert a string of ASCII code into the corresponding string of characters. 需要将一个ASCII码字符串转换为相应的字符字符串。 String.fromCharCode() works only if I directly type in the ASCII codes but I need to use a variable name for this. String.fromCharCode()仅在我直接输入ASCII代码但我需要为此使用变量名时才有效。

code = codeArr.join('.'); // 104,101,108,108,111,32,119,111,114,108,100 // 104,101,108,108,111,32,119,111,114,108,100

String.fromCharCode(104,101,108,108,111,32,119,111,114,108,100); // hello world // 你好,世界

String.fromCharCode(code); // this returns blank? //返回空白? No errors just blank 没有错误就只是空白

Use Spread syntax . 使用Spread语法

 let code = [104,101,108,108,111,32,119,111,114,108,100]; console.log(String.fromCharCode(...code)); 

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

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