Technique: Integer to String Conversion

19 July 2021 by Phillip Johnston • Last updated 15 December 2021There are many cases where we want to use a character- or string-based representation for an element in our system. However, programmatically we often prefer to work with integers or enumerations. In Timeless Laws of Software Development, Jerry Fitzpatrick suggests a simple approach for converting between the integral representation and the character it represents. We generate an array of characters, using the integral value as an index into the array. private static string rankString = “_A123456789TJKQ”; public char RankToIdentifier(ushort rank) { return rankString[rank]; } The same idea can be …

To access this content, you must purchase a Membership - check out the different options here. If you're a member, log in.