Formatting int as a ASCII char

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pb2000
    New Member
    • Apr 2010
    • 13

    Formatting int as a ASCII char

    Hello,

    I must present integers as a ASCII chars.
    For instance for num 65 -> str1 "A".
    int num = 65;
    string str1 = String.Format(" {0:??}",num);

    Mentioned problem cannot be solved with Encoding.ASCII. .. and others, because of the fact that I use specified "C# like" environment with only String.Format method for that.

    I would be grateful for Your help.
    Thanks a lot!

    pb2000
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    Try casting the int to a char and appending to a string.

    Code:
                int aCode = 65;
    
                string resultStr = "" + (char)aCode;
    
                Console.WriteLine(resultStr);

    Comment

    Working...