LoginSignup
3
4

More than 5 years have passed since last update.

[C#]Excel列名変換問題を解く

Posted at

Excel列名変換問題で第2回社内プログラミングコンテストを開催してみた(前編) - give IT a try

少し必要になったのとLINQの勉強のため
必要になったのは列名から数字のほうだけだったのでそれのみ。
LINQはなかなか使いやすいと思った。

public static int ToInt(string str)
{
    return str
        .ToCharArray()
        .Reverse()
        .Select((c, i) => new KeyValuePair<int, int>(i, (int)c - (int)'A' + 1))
        .Aggregate(0, (sum, pair) => sum + pair.Value * (int)Math.Pow(26, pair.Key));
}
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4