in c#, how can i build up array from A to ZZ that is similar to the way that excel orders columns

后端 未结 10 960
情深已故
情深已故 2020-12-18 00:48

i am looking for code that can generate an array where the first item is A, then B, then C . . .after Z i

10条回答
  •  隐瞒了意图╮
    2020-12-18 01:16

    To complement Vlad's answer, here's the reverse operation of ToBase26(int):

    static long ToBase10(string str)
    {
       if (string.IsNullOrWhiteSpace(str)) return 0;
       var value = str[0] - 'A' + 1;
    
       return (long) (value * Math.Pow(26, str.Length - 1) + 
              ToBase10(str.Substring(1, str.Length - 1)));
    }
    

提交回复
热议问题