|
|
 |
 |
 |
 |
TCL(Tool Command Language) Scripting
|
 |
 |
 |
 |
 |
 |
 |
 |
Question about UTF-8
I use TCL PRO 1.4 on windows xp and have a tcl program that receives a already created ANSI coded text file. How can I convert this file to a UTF-8 coded text file as easy as possible. Can I do it without opening it? Regards Bjarte
On May 10, 2:19 am, b@docstream.no wrote: > I use TCL PRO 1.4 on windows xp and have a tcl program that receives a > already created ANSI coded text file. > How can I convert this file to a UTF-8 coded text file as easy as > possible. Can I do it without opening it? > Regards > Bjarte
Assuming that by "ANSI" you mean ASCII, you don't need to do anything. A nice feature of UTF-8 is that it is a superset of ASCII. An ASCII file is therefore already in UTF-8.
b @docstream.no <b @docstream.no> wrote: > I use TCL PRO 1.4 on windows xp and have a tcl program that receives a > already created ANSI coded text file. If you say "receive", I take it that you're reading it in through a channel. (and it doesn't matter if this channel is a socket, a file or a pipe) do: fconfigure $channel -encoding $enc before the actual reading, where $enc can be windows-1252, koi8-r, iso8859-15, or whatever else your data is encoded with. (I don't know any encoding named just "ansi")
billpo @alum.mit.edu wrote: > On May 10, 2:19 am, b @docstream.no wrote: >>I use TCL PRO 1.4 on windows xp and have a tcl program that receives a >>already created ANSI coded text file. >>How can I convert this file to a UTF-8 coded text file as easy as >>possible. Can I do it without opening it? >>Regards >>Bjarte > Assuming that by "ANSI" you mean ASCII, you don't need to do anything. > A nice feature of UTF-8 is that it is a superset of ASCII. An ASCII > file is therefore already in UTF-8.
"ANSI" is probably some of the windows encodings. In a non-English world, you need to convert (for example Norwegian has a slashed o). And of course the file has been opened. Then use "fconfigure -encoding" to explicitly set the input encoding. The following snippet converts a file from latin-1 encoding to UTF-8: set fdr [open "l1t.txt" r] fconfigure $fdr -encoding iso8859-1 set fdw [open "utf8t.txt" w] fconfigure $fdw -encoding utf-8 while { [gets $fdr line] >=0 } { puts $fdw $line }
close $fdw close $fdr For Winansi you have to look up the right encoding name. Christian
On May 10, 4:05 am, Christian Gollwitzer <Christian.Gollwit...@uni-
bayreuth.de> wrote: > billpo @alum.mit.edu wrote: > > On May 10, 2:19 am, b @docstream.no wrote: > >>I use TCL PRO 1.4 on windows xp and have a tcl program that receives a > >>already created ANSI coded text file. > >>How can I convert this file to a UTF-8 coded text file as easy as > >>possible. Can I do it without opening it? > >>Regards > >>Bjarte > > Assuming that by "ANSI" you mean ASCII, you don't need to do anything. > > A nice feature of UTF-8 is that it is a superset of ASCII. An ASCII > > file is therefore already in UTF-8. > "ANSI" is probably some of the windows encodings.
Of course one can't be certain what the poster means by "ANSI", but the only encoding in common usage that is an ANSI standard is ASCII. ASCII is ANSI X3.4 (which has both a 1977 version and a 1986 revision).
|
 |
 |
 |
 |
|