How to get a Char from an ASCII Character Code in c#

前端 未结 3 720
盖世英雄少女心
盖世英雄少女心 2020-12-09 14:31

Im trying to parse a file in c# that has field (string) arrays separated by ascii character codes 0, 1 and 2 (in Visual Basic 6 you can generate these by using Chr(0) or Chr

3条回答
  •  天命终不由人
    2020-12-09 15:09

    You can simply write:

    char c = (char) 2;
    

    or

    char c = Convert.ToChar(2);
    

    or more complex option for ASCII encoding only

    char[] characters = System.Text.Encoding.ASCII.GetChars(new byte[]{2});
    char c = characters[0];
    

提交回复
热议问题