如何将字符串中的每个字符转换为数字以进行编码。
我的编码键是。
a = 01
b = 02
c = 03
d = 04
.
.
z = 26
因此,假设我在单元格中输入“ dog”,则应将其转换为“ 04 15 07”。
将可在Google Spreadsheet中使用,因此JavaScript函数会有所帮助。
最佳答案
根据您的评论,我创建了以下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;
}
您要做的就是调用该函数,它将为您提供Example的数字代码:
GiveNumbercode(“ dog”)将返回“您的编号:04 15 07”
关于javascript - 自定义编码字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31786358/