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"
Run
- Convert string to char greenfork
- Re: Convert string to char Stefan_Salewski
- Re: Convert string to char greenfork
- Re: Convert string to char Araq
- Re: Convert string to char cdome
- Re: Convert string to char mashingan
- Re: Convert string to char juancarlospaco
