Re: Bests way to handle lines in files with only a return character?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

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

From: <slebetman@yahoo.com>
Date: Fri Dec 30 2005 - 00:44:32 CET

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 ...
Received on Tue Jan 3 03:09:41 2006