I'm implementing a compiler, and I need to convert from an escape character literal written in source code file to an actual value.
For example I might have a line of source code char = '\\'
. I then parse that and get given the string "'\\'"
, which I need to turn into the actual char '\\'
.
char.Parse
and char.TryParse
both fail when parsing a char in escape sequence form. For example:
char.Parse(@"\\");
Will throw "String must be exactly one character long."
Is there any way to parse everything on this list as a char (ignoring those that are to big to fit in a UTF16 char).