Hello, my problem is this:
From a lexer I receive a string containing the value of a character literal, for example:
'A'
'B'
'+'
'\n'
From these strings I want to obtain its corresponding UNICODE code, since it is a string, the first thing I do is trim the string with the character (single quote) "'"
, so I get the following strings
A
B
+
\n
From the above strings I would like to get the UNICODE code value and store it, what I have tried is the following:
trimmedValue := strings.Trim(charLiteral, "'")
chars := []rune(trimmedValue)
From here I can get the value for the first three cases, 65
, 66
, 43
but how to convert the string \n to its unicode value, since in this way I get a slice of two different values, that is, how to make \n be interpreted as a only value/character? Is there a direct way to do it?
Thanks