Re: Bests way to handle lines in files with only a return character?



Keith wrote:
> I am running into a problem with lines in a file
> I am retrieving that only have a return character in them.
> What is the best way to detect lines with only that character
> in them?
> Example
> 123.456780
> 123.567890
>
> 123.999999
> 123.888888
>
> 123.777777
>
> TIA,
>

I usualy do something like:

set line [string trim $line]
if {$line != ""} {
# Process line here ...

This way you also handle lines containing spacebars and tabs. It's also
easy to handle coments in the file in a similar fashion:

set commentChar "//"
set n [string first $commentChar $line]
if {$n != -1} {
set line [string range $line $n end]
}
set line [string trim $line]
if {$line != ""} {
# Notice that a line with only a comment
# is automatically ignored.
# Process line here ...

.



Relevant Pages