How would one create a char or string constant containing the single character ASCII 127?
// Normal printing character - no problems
const char VPIPE = '|';
//error "The expression being assigned to 'DEL' must be constant"
const char DEL = new string(127, 1);
It would also be OK if the constants were strings instead of chars:
const string VPIPE = "|";
const string DEL = "???";
I know that ASCII 127 isn't something you can 'type' at the keyboard, but there has to be a way to create a string or char constant from it (or use a built-in one that I haven't found).
Personally I would use a "\u" escape sequence:
const char Delete = '\u007f';
I'm not keen on the "\x" escape sequence mentioned elsewhere - it isn't too bad in character literals (where multiple characters => compiler error), but it can be nasty for string literals:
// Tab the output
Console.WriteLine("\x9Good line");
Console.WriteLine("\x9Bad line");
Assuming you can see the bug here, how certain are you that you'd have avoided it when making "just a quick change"?
Given that I'm avoiding it for string literals, I think it makes sense to be consistent and just use "\u" everywhere that I want to escape a hex value.
'\x7F'
will do it (and can also be embedded in a string if necessary).
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