如何将字符串中的每个字符转换为编码数字。
我的编码密钥将是。
a = 01
b = 02
c = 03
d = 04
.
.
z = 26
所以我想进入" dog"在我的单元格中,它应该转换为" 04 15 07"。
将在Google电子表格中使用,因此JavaScript函数会有所帮助。
答案 0 :(得分:2)
根据您的评论,我创建了以下Javascript代码:
var letters = ["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"];
function giveNumbercode(someString){
var numbercode="";
for(var i = 0; i < someString.length; i++){
var letter = someString[i];
var number = letters.indexOf(letter) + 1;
if(number < 10){
number = "0"+number
}
numbercode += " "+number
}
alert("Your Numbercode: "+numbercode+"");
return numbercode;
}
所有你需要做的就是调用函数,它会给你一个例子的数字代码:
giveNumbercode(“dog”)将返回“您的号码:04 15 07”
答案 1 :(得分:0)