Created
December 3, 2018 15:56
-
-
Save sasrai/4a2d173f2014c659e2f4c78dc635ffb2 to your computer and use it in GitHub Desktop.
Excel Column Num to Alpha-26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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