Board index » delphi » Couple of quick questions regarding txt files...

Couple of quick questions regarding txt files...

The application is a delphi console app....

After opening a txt file for reading, is there a command to jump to the next
line of the text file without having to read that line?

Also, if the text file were to contain a paragraph, then a blank line, then
another paragraph, how's the best way to get delphi to take notice of that
blank line and stop reading at that point  (or even start reading at that
point)

 

Re:Couple of quick questions regarding txt files...


On Sun, 26 May 2002 11:10:54 +1000, "Embercide"

Quote
<emberc...@optushome.com.au.NOSPAM> wrote:
>The application is a delphi console app....

>After opening a txt file for reading, is there a command to jump to the next
>line of the text file without having to read that line?

Readln();  Given thus, with no argument, will advance the reading
operation to the next line, discarding whatever input remains on the
current line.

Quote

>Also, if the text file were to contain a paragraph, then a blank line, then
>another paragraph, how's the best way to get delphi to take notice of that
>blank line and stop reading at that point  (or even start reading at that
>point)

readln(x); where x is a variable of type string, should do it. If you
check the length of the string returned in x, it will be zero for an
empty line. Of course if you have a line with nothing in it but
whitespace, it will look to you like an empty line, but length(x) will
return a value greater than zero.
Quote

Al Moore

Re:Couple of quick questions regarding txt files...


Hey thanks for that :)
It always seems to be the obvious things that I miss :)

Quote
"Alan Moore" <alan.s.mo...@attbi.com> wrote in message

news:3cf04011.928140@netnews.attbi.com...
Quote
> On Sun, 26 May 2002 11:10:54 +1000, "Embercide"
> <emberc...@optushome.com.au.NOSPAM> wrote:

> >The application is a delphi console app....

> >After opening a txt file for reading, is there a command to jump to the
next
> >line of the text file without having to read that line?

> Readln();  Given thus, with no argument, will advance the reading
> operation to the next line, discarding whatever input remains on the
> current line.

> >Also, if the text file were to contain a paragraph, then a blank line,
then
> >another paragraph, how's the best way to get delphi to take notice of
that
> >blank line and stop reading at that point  (or even start reading at that
> >point)

> readln(x); where x is a variable of type string, should do it. If you
> check the length of the string returned in x, it will be zero for an
> empty line. Of course if you have a line with nothing in it but
> whitespace, it will look to you like an empty line, but length(x) will
> return a value greater than zero.

> Al Moore

Re:Couple of quick questions regarding txt files...


ok i've gotten myself stuck already...
What I want to do is skip over the lines in the text file until I come to
the blank line, what I have is....

      while not eof(filename) do
         begin
            while not eoln(filename) do
               begin
                  readln
               end;

I did a "trace into" in delphi to see where it stops, and when it gets to
that end; it just sits there and doesnt loop the readln

Quote
"Alan Moore" <alan.s.mo...@attbi.com> wrote in message

news:3cf04011.928140@netnews.attbi.com...
Quote
> On Sun, 26 May 2002 11:10:54 +1000, "Embercide"
> <emberc...@optushome.com.au.NOSPAM> wrote:

> >The application is a delphi console app....

> >After opening a txt file for reading, is there a command to jump to the
next
> >line of the text file without having to read that line?

> Readln();  Given thus, with no argument, will advance the reading
> operation to the next line, discarding whatever input remains on the
> current line.

> >Also, if the text file were to contain a paragraph, then a blank line,
then
> >another paragraph, how's the best way to get delphi to take notice of
that
> >blank line and stop reading at that point  (or even start reading at that
> >point)

> readln(x); where x is a variable of type string, should do it. If you
> check the length of the string returned in x, it will be zero for an
> empty line. Of course if you have a line with nothing in it but
> whitespace, it will look to you like an empty line, but length(x) will
> return a value greater than zero.

> Al Moore

Re:Couple of quick questions regarding txt files...


hi,

"Embercide" <emberc...@optushome.com.au.NOSPAM> schrieb im Newsbeitrag news:3cf0495a$0$15149$afc38c87@news.optusnet.com.au...

Quote
> ok i've gotten myself stuck already...
> What I want to do is skip over the lines in the text file until I come to
> the blank line, what I have is....

>       while not eof(filename) do
>          begin
>             while not eoln(filename) do
>                begin
>                   readln
>                end;

> I did a "trace into" in delphi to see where it stops, and when it gets to
> that end; it just sits there and doesnt loop the readln

[...]

var s: string;

s:='';
 while (not eof(filename)) and (s<>'') do readln(s);

Re:Couple of quick questions regarding txt files...


On Sun, 26 May 2002 12:32:56 +1000, "Embercide"

Quote
<emberc...@optushome.com.au.NOSPAM> wrote:
>ok i've gotten myself stuck already...
>What I want to do is skip over the lines in the text file until I come to
>the blank line, what I have is....

>      while not eof(filename) do
>         begin
>            while not eoln(filename) do
>               begin
>                  readln
>               end;

>I did a "trace into" in delphi to see where it stops, and when it gets to
>that end; it just sits there and doesnt loop the readln

Did you mean to say "readln(filename)"?  If you just do a "readln",
that will come from the keyboard, not from the filename!

Bob Schor
Pascal Enthusiast

Other Threads