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

Jimbo picture Jimbo · Aug 5, 2010 · Viewed 266.3k times · Source

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(1) etc.)

I know that for character code 0 in c# you can do the following:

char separator = '\0';

But this doesnt work for character codes 1 and 2?

Answer

Jon Skeet picture Jon Skeet · Aug 5, 2010

Two options:

char c1 = '\u0001';
char c1 = (char) 1;