encoding convertto

Difference between version 10 and 11 - Previous - Next
    :   '''`[encoding] convertto`''' ?''encoding''? ''string''
Convert ''string'' from Unicode to the specified ''encoding''. 
The result is a sequence of bytes (i.e., a byte array) that represents the converted string. 
Each byte is stored in the lower 8-bits of a Unicode character. 
If ''encoding'' is not specified, the current [encoding system%|%system encoding] is used.
<<discussion>>
[ZB] ...and what then? How to convert such "byte array" into "ordinary string", which uses chosen ISO-encoding - can be [encoding system] - and which uses single-byte characters?)
<<br>>
** See Also **


   [GSM 03.38 encoding]:   Example of an encoding with "non-null" 0 character.



** Description **

Converts ''string'' from [Unicode] to the specified ''encoding''.  The result
is a string where each character represents the next byte in the resulting byte
sequence.  I.e., each byte is represented by the lower 8-bits of a Unicode
character. 

If ''encoding'' is not specified, the current [encoding
system%|%system encoding] is used.



** Discussion **

[ZB]: ...and what then? How to convert such "byte array" into "ordinary string", which uses chosen ISO-encoding - can be [encoding system] - and which uses single-byte characters?)

[DKF]: Depends what you want to do really, yes? It's useful with [binary format]'s `a` and `A` conversions, and you can communicate it externally over channels that are using the `iso8859-1` encoding. Or that you [chan configure%|%configure] to be `-translation binary` or `-encoding binary`. To be clear, “byte arrays” ''are strings'' where the characters are all from the range `U+000000`–`U+0000FF`; they also happen to have a more efficient internal representation, but that's not very important, a fact that you should ignore.

[ZB] Is this a method (external communication over channels) used by msgcat-tools? No, I didn't analyse its code yet; I was just trying to use "convert" to perform conversions - according to its name - with no desired result.----
Example of an encoding with "non-null" 0 character: [GSM 03.38 encoding]
<<discussion>>
----
**See also**
   * [encoding]
   * [encoding convertfrom]
   * [encoding names]
   * [encoding system]


<<categories>> Ctcl command | Tcl syntax help | Binary Data