如何将一串ascii码转换成文本?

How to covert a string of ascii codes to text?

我有一个返回为“104,101,108,108,111”的 ascii 字符代码列表,我正在尝试将它们转换回字符串:

response = '104,101,108,108,111'
String.fromCharCode(response)

当我将其传递给 String.fromCharCode(response) 时,我得到 ' ' 作为响应,但是当我像下面这样传递输入时,我能够得到正确的响应:

String.fromCharCode(104,101,108,108,111)

如果我们有一串代码作为响应,我们如何传递数字代码?

您需要将您的字符串转换为单独的参数:用逗号分隔并展开:

let response = '104,101,108,108,111';
let result = String.fromCharCode(...response.split(","));
console.log(result);