Encode the given number into a Base36 string - CSharp System

CSharp examples for System:String Base

Description

Encode the given number into a Base36 string

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from  ww w. j  av  a2 s. c o  m*/

public class Main{
        /// <summary>
        /// Encode the given number into a Base36 string
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static String Encode(long input)
        {
            string CharList = "0123456789abcdefghijklmnopqrstuvwxyz";
            
            if (input < 0) throw new ArgumentOutOfRangeException("input", input, "input cannot be negative");

            char[] clistarr = CharList.ToCharArray();
            var result = new Stack<char>();
            while (input != 0)
            {
                result.Push(clistarr[input % 36]);
                input /= 36;
            }
            return new string(result.ToArray());
        }
}

Related Tutorials