var
s1: string = "a"
s2: string = r"\n"
c1: char
c2: char
c1 = @s1[0]
c2 = ???
How do I convert the string r"\n" to its char representation '\n'?
You can't generically represent string as char, but for your specific case, you can do it like this:
import options
proc chr(s: string): Option[char] =
if s == "\\n": some('\n')
else: none(char)
let nlinerepr = r"\\n".chr
if nlinerepr.isSome:
echo nlinerepr.some
let otherstr = "hello".chr
if otherstr.isNone:
echo "no char repr"