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?
Try this: char c = 'a'; // or whatever your character is printf("%c %d", c, c); The %c is the format string for a single character, and %d for a digit/integer. By casting the char to an integer, you'll get the ascii value.
Two options:
char c1 = '\u0001'; char c1 = (char) 1;
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With