Increment an index that uses numbers and characters (aka Base36 numbers)

后端 未结 4 788
感动是毒
感动是毒 2021-01-19 19:08

I have a string based code that can be either two or three characters in length and I am looking for some help in creating a function that will increment it.

Each \'

4条回答
  •  死守一世寂寞
    2021-01-19 19:44

    Does this do what you need?

    public class LetterCounter
    {
        private static readonly string[] _charactersByIndex = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    
        public string GetStr(int i)
        {
            if (i < _charactersByIndex.Length)
                return _charactersByIndex[i];
    
            int x = i / (_charactersByIndex.Length - 1) - 1;
            string a = _charactersByIndex[x];
            string b = GetStr(i - (_charactersByIndex.Length - 1));
            return a + b;
        }
    }
    

    }

提交回复
热议问题