Convert A to 1 B to 2 … Z to 26 and then AA to 27 AB to 28 (column indexes to column references in Excel)

后端 未结 4 669
刺人心
刺人心 2020-12-05 14:20

Does any one have algorithm or logic to Convert A to 1 ,B to 2, ... ,Z to 26 and then ,AA to 27, AB to 28 etc.

In other words, converting a column index into the col

4条回答
  •  天命终不由人
    2020-12-05 14:42

    Same problem, different language: PHP.

    function charToInt($char)
    {
       $array = array_flip(range(a, z));
       return $array[$char] + 1;
    }
    
    echo charToInt('c');
    
    outputs: 3
    

提交回复
热议问题