Re: Handling escaped chars (using \ char) from a user



Johnny Cybermyth schrieb:
I'm writing a plugin for a serial port program and need to support
sending non ASCII chars. I would like to allow the user to express
non-ASCII chars in a simple hex escape format: \01 \0D etc

So a sample string would be input as:
\01A01TEST\02
which would be interpreted as a string of these hex chars:
01 41 30 31 54 45 53 54 02

I'm new to TCL so any ideas on better ways to get this done is appreciated.
Tcl has a fine encoding subsystem for all kinds of non-ascii chars. If
it fits into the basic multilingual plane of unicode you can use it in Tcl.
There is already an escape mechanism for unicode characters like this:
\u20ac (euro symbol)
you can also use other escapes like \0x but the \u escapes are the most
useful.

See for some examples:
http://wiki.tcl.tk/encoding
http://wiki.tcl.tk/515
http://wiki.tcl.tk/binary

If you want to process arbitraty binary data look at the [binary] commands.

If you tell us a bit more of what you have to do, we can probably help
you to find a good solution.

Michael
.



Relevant Pages