Decode the Base36 Encoded string into a number - CSharp System

CSharp examples for System:String Base

Description

Decode the Base36 Encoded string into a number

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//w  ww  .j a v a2 s. c  o  m

public class Main{
        /// <summary>
        /// Decode the Base36 Encoded string into a number
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static Int64 Decode(string input)
        {
            string CharList = "0123456789abcdefghijklmnopqrstuvwxyz";
            var reversed = input.ToLower().Reverse();
            long result = 0;
            int pos = 0;
            foreach (char c in reversed)
            {
                result += CharList.IndexOf(c) * (long)Math.Pow(36, pos);
                pos++;
            }
            return result;
        }
}

Related Tutorials