Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
IntToExcelColumnNotation
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { for (int i = 1; i < 1000; i++) { Console.WriteLine(i + " = "+ConvertToLetters(i)); } } public static string ConvertToLetters(int input) { if (input < 1) { throw new ArgumentException("invalid input"); } var baseNum = 26; var asciiBase = 64; var quotient = input; var remainder = 0; List<char> result = new List<char>(); while (quotient >= baseNum ) { remainder = quotient % baseNum ; remainder = remainder == 0? 26 : remainder; result.Add((char) (remainder+asciiBase )); quotient = (quotient - remainder) / baseNum ; } if (quotient > 0) { result.Add((char) (quotient+asciiBase )); } result.Reverse(); return new string(result.ToArray()); } } }
run
|
edit
|
history
|
help
0
array int
Date example
GP-TIME
proxy
Subdomain regex
Plt-D v.0.8.5
ConcurrentStack<T>
quick sort final
encypt& dcrypt
321