WJG (26/JUN/11) A while ago Richard Suchenwirth posted the following very useful proc to convert Unicode screen characters to ascii code values.
#---------------
# convert unicode character to ascii escape sequence
# source: https://wiki.tcl-lang.org/515
#---------------
proc u2a {s} {
set res ""
foreach i [split $s ""] {
scan $i %c c
if {$c<128} {append res $i} else {append res [format %04.4X $c]}
}
return $res
} ;#RS
But, what if it's necessary want to convert the other way around, from codes to characters? It seems to me that there are two ways to do the job:
#~~~~~~~~~~~~~~~
# convert unicode to character
# U+3405
#~~~~~~~~~~~~~~~
proc unicode2char { code } {
eval set str "\\u[string map "U+ {}" $code]"
}
proc uni2char {code} {
set val [scan $code "U+%x"]
return [format %c $val]
}