javascript 获取字符递增

比如A->B,AA->AB,Z->AA

参考https://blog.csdn.net/xiaotao2004/article/details/75096607

C#版本,改写为javascipt版本

//获取字符递增
function GetNextChars(letter)
{
    var letterTemp = letter.toUpperCase();
    var length = letterTemp.length;
    var res = 0;
    for (var i = 0; i < length; i++)
    {
        res = res * 26 + letterTemp.charCodeAt(i) - 65 + 1;
    }
    res++;

    var endCol = '';
    var endColSignal = '';
    var iCnt = Math.round(res / 26);
    if (res >= 26 && res % 26 === 0) {
        var icell = iCnt - 2;
        endCol = (icell < 0 ? "" : String.fromCharCode(65 + icell)) + 91;
    }
    else {

        endColSignal = (iCnt === 0 ? "" : String.fromCharCode(65 + (iCnt - 1)));
        var icell1 = res - iCnt * 26 - 1;
        if (icell1 < 0)
            icell1 = 0;
        endCol = endColSignal + String.fromCharCode(65+ icell1);
    }
    return endCol;
}

 

转载于:https://www.cnblogs.com/zhaogaojian/p/10786428.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值