【发布时间】:2021-03-31 14:07:09
【问题描述】:
我的编码器出现问题,因为它没有按预期工作。
通过在我的 html 页面中添加的输入声明的变量“消息”
var ENCODE_OPC = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6','7','8', '9', '0', ' '];
var DECODE_OPC = ['&2p', '&4g', '&6g', '&7b', '&4v', '&8n', '&4b', '&1d', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6','7','8', '9', '0', ' '];
for (var q = 0; q < 63; q++) {
message.replace(ENCODE_OPC[q], DECODE_OPC[q]);
}
console.log(message);
【问题讨论】:
-
replace()返回一个新字符串。 -
and replace 只替换一个实例
标签: javascript decoder