Incrementing alphabets

前端 未结 5 1919
轮回少年
轮回少年 2020-12-19 13:29

I am trying to create a function which will give me alphabet position when an index is passed. It will be same like how excel shows it\'s columns. A...Z, AA,AB.... I wrote t

5条回答
  •  情深已故
    2020-12-19 14:08

    static string GetColumnName(int index)
    {
        const int alphabetsCount = 26;
        string result = '';
    
        if (index >= alphabetsCount)
        {
            result += GetColumnName(index-alphabetsCount)
        }
        return (string) (64 + index);
    }
    

    My C# is HORRIBLE AND RUSTY. Interpret this as pseudocode - it will almost certainly not compile, but may get you started.

提交回复
热议问题