数字序号 转 字母序号

 

/*
* 数字序号转字符串序号 0 => "A"
*/
function indexToString(index){
  var charcode;
  return index.toString(26).split("").map(function(item,i){
    charcode = item.charCodeAt(0);
    charcode+=(charcode>=97?10:49);
    return String.fromCharCode(charcode)
  }).join("").toUpperCase();
}

/*
* 字符串序号转数字序号 "A" => 0
*/
function stringToIndex(str){
  var charcode;
  return parseInt(str.toLowerCase().split("").map(function(item,i){
    charcode = item.charCodeAt(0);
    charcode-=(charcode<107?49:10);
    return String.fromCharCode(charcode)
  }).join(""),26);
}


indexToString(984284) => "CEABC"
stringToIndex("CEABC") => 984284

 


原文链接:https://blog.csdn.net/zq1988626/article/details/90693723

posted @ 2022-02-28 10:26  Echo的前端空间  阅读(87)  评论(0编辑  收藏  举报