Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control characters in a string

Status
Not open for further replies.

hija

Programmer
Oct 30, 2002
16
AU
I am in the process of writing a Tcl script that processes lines from a file and extracts specific information to format in a readable manner.
Some of the files contain hidden control characters or a single quote mark or a single brace. These need to be ignored so the string can be assigned to a string array location for processing. One character that turns up in the first line in a small percentage of files causes Tcl to think that no further data is in the line and provides error messages such as "Missing " when attempting to 'set each_line(1)' ....
I am pretty sure the control character is \u0003 'ETX'. This means that the script grinds to a halt and I can no longer process further files.
Is there any way I can get Tcl to ignore/replace or at least allow me to step over this file "logging it" and proceeding to process the next file.
I have already tried to use [string replace] and [catch]
to detect in advance to be able to move on to the next file but to no avail...
Any ideas?
 
Additional Information...
I have done some more investigation into this control character and it appears to be a End of Medium 'EM' ASCII Char 25(decimal), it is this one I cannot get Tcl to ignore in the string being read from a file.
hija
 
I can't get tcl to even format this control character.
Try comp.lang.tcl and get some expert advice on how to deal with this problem.

I'd say try something like this first to make sure
it doesn't read eof prematurely.
Code:
   while {[gets $fd line] > -1} {
           puts "$line"
   }
 
Thanks for the hint marsd, it looks as if this is it, now I need a way of overiding it, Im going to try the string map function to change it in advance of processing
hija
 
Solved the problem by using

fconfigure 'fileID' -eofchar { }
this now allows the complete string to be taken for processing.
Thanks marsd for pointing me in the right direction.
hija
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top