Tuesday 20 September 2016

generate alphachar in C#


    private class ProgramTest
    {
        private static void Main(string[] args)
        {
            for (int i = 1; i < 100; i++)
            {
                var abc = TestA.GetColumnNameFromIndex(i);
                Console.WriteLine(abc);
            }
      }
}

----------------------

public  class TestA
    {
        public static int Number;
        public static String GetColumnNameFromIndex(int column)
        {
            column--;
            String col = Convert.ToString((char)('A' + (column % 26)));
            while (column >= 26)
            {
                column = (column / 26) - 1;
                col = Convert.ToString((char)('A' + (column % 26))) + col;
            }
            return col;
        }
    }

No comments:

Post a Comment