String length of a binary string?
Quote:
> This is probably a "D'oh!" kind of question, but...
> If I read from a file configured with "fconfigure -translation binary
> -encoding binary" and all that sort of stuff, and I get a string back,
> how do I know how many bytes are in the string?
> fconfigure $f -translation binary -encoding binary
> set s [read $f 1024]
> How do I know how many bytes I read, if the file is less than 1024 bytes
> long? Isn't "$s" going to be interpreted in UTF-8 characters if I ask
> "[string length $s]"? I would have thought there would be a "string
> bytes $s" or some such? Do I really have to go through [binary] and
> [llength] or some such to find out the number of bytes in a string?
"string length" returns the number of characters in the string. In the case of
binary data, each binary byte is stored as a single character, so "[string
length $s]" should return the number of bytes in the binary data. Note this is
not the same as the amount of storage used by Tcl to represent the data, but
that should not be relevant to your script.
___________________________________________________________
Scott Stanton 650-210-0105 tel
Sr. Software Engineer 650-210-0101 fax
The Tcl Platform Company http://www.scriptics.com