Skip to content

Instantly share code, notes, and snippets.

@sasrai
Created December 3, 2018 15:56
Show Gist options
  • Save sasrai/4a2d173f2014c659e2f4c78dc635ffb2 to your computer and use it in GitHub Desktop.
Save sasrai/4a2d173f2014c659e2f4c78dc635ffb2 to your computer and use it in GitHub Desktop.
Excel Column Num to Alpha-26
using System.Text;
public class Hello{
public static void Main(){
// Your code here!
System.Console.WriteLine("Hello C#");
System.Console.WriteLine($"??? => {DIC_ALPHABET[0]}");
for (int i = 1; i <= 16384; i++)
System.Console.WriteLine($"{i} => {numToAlphabet(i)}");
}
private const string DIC_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static string numToAlphabet(int num) {
var sb = new StringBuilder();
while (num > 0) {
var mod = (num - 1) % DIC_ALPHABET.Length;
sb.Insert(0, DIC_ALPHABET[mod]);
num = (num - mod) / DIC_ALPHABET.Length;
}
return sb.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment