-
1
- #1
This tip is passed on from attempting to solve a problem in formatting a string of characters by eliminating control and field key characters.
Using [string map] function enables one to translate a range of odd characters in a string used to separate fields.
string map {ª _ ô _ ² _ Ø _ > _} "Fvx @ ª>Part No 1234 ô Use date/time 190337 APR 02 ²>Ø"
will out put a line
"Fvx @ __Part No 1234 _ Use date/time 190337 APR 02 ___
This improves readablity from the human viewpoint.
If you have a spurious EOF character in a string being read from a file this upsets Tcl to the point where you cannot process any further lines after. To override the EOF character in a string use fconfigure
set fileName [open $unformatted_file r ]
fconfigure fileName -eofchar { }
"process file of text line by line here"
close $fileName
Using [string map] function enables one to translate a range of odd characters in a string used to separate fields.
string map {ª _ ô _ ² _ Ø _ > _} "Fvx @ ª>Part No 1234 ô Use date/time 190337 APR 02 ²>Ø"
will out put a line
"Fvx @ __Part No 1234 _ Use date/time 190337 APR 02 ___
This improves readablity from the human viewpoint.
If you have a spurious EOF character in a string being read from a file this upsets Tcl to the point where you cannot process any further lines after. To override the EOF character in a string use fconfigure
set fileName [open $unformatted_file r ]
fconfigure fileName -eofchar { }
"process file of text line by line here"
close $fileName