-3

I have a List<int> that contains incremental integers like 1,2,3,4 .
How can I convert the 'list' . I'm looking for an algorithm or code to change numbers to 'corresponding' letters.

 List<string>

From: 1, 2, 3, 4, 5

To : A, B, C, D, E.... AA, AB etc.

Change the increments from 1,2,3 to A, B, C

Jon
  • 1,608
  • 7
  • 25
  • 38
  • What have you tried so far? Probably a look at a codepage (like [ASCII](http://www.asciitable.com/) could help you? – Markus Safar May 27 '21 at 14:17
  • 1
    Does this answer your question? [Convert character to its alphabet integer position?](https://stackoverflow.com/questions/20044730/convert-character-to-its-alphabet-integer-position) –  May 27 '21 at 14:21

1 Answers1

1

You could do a simple math. ie:

void Main()
{
    var intList = Enumerable.Range(1, 1000);
    var alphaList = intList.Select(x => ToAlpha(x));
    foreach (var x in alphaList)
    {
        Console.WriteLine(x);
    }
}

private static string ToAlpha(int i)
{
    string result = "";
    do
    {
        result = (char)((i-1) % 26 + 'A') + result;
        i = (i-1)/26;
    } while (i > 0);
    return result;
}
Cetin Basoz
  • 22,495
  • 3
  • 31
  • 39