【发布时间】:2019-07-09 19:49:08
【问题描述】:
我有一个像“iyxnhel2jeh”这样的字符串,我想为每 2 个字节将它们拆分为一个 var。
var string = "iyxnhel2jehe";
var final = "";
while (/*String still has bits*/) {
switch (/*Two byte of string*/) {
case "iy":
final += "x";
break;
case "xn":
final += "o";
break;
case "he":
final += "g";
break;
case "l2":
final += "k";
break;
case "je":
final += "e";
break;
default:
final += "none"
}
}
剪断这个字符串的最好方法是什么?
【问题讨论】:
-
给定字符的字节数取决于编码...你的意思是你只想每两个字符分割一个字符串?
-
你的意思是
bytes,还是真的是characters? -
这可以通过带有 indexOf 和 else 而不是循环的 if 语句来完成
标签: javascript string while-loop switch-statement