Search code examples
c#character-encodingasciiescaping

How to get a char from an ASCII Character Code in C#


I'm 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 doesn't work for character codes 1 and 2?


Solution

  • Two options:

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