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

Reply via email to