Board index » delphi » Text Files

Text Files

Hi,
    I am learning Pascal at collage. I was wanting help with text files. In
the text file is a list of email address each on a single line. But what I
want to do is search the text file for email address with .ac.uk at the end.
Any one with a ideas would be very helpful
    thanks
    Jonathan
 

Re:Text Files


On Thu, 25 Mar 1999 19:07:24 -0000, "Jonathan Malcolm"

Quote
<j...@malco.freeserve.co.uk> wrote:
>Hi,
>    I am learning Pascal at collage. I was wanting help with text files. In
>the text file is a list of email address each on a single line. But what I
>want to do is search the text file for email address with .ac.uk at the end.
>Any one with a ideas would be very helpful
>    thanks
>    Jonathan

var     f:text;
        s,sub:string;
begin
        sub:='.ac.uk';
        assign(f,'file.txt');
        reset(f);
        while not eof(f) do begin
                readln(f,s);
                if pos(sub,s)<>0 then
                        writeln(s)
        end;
        close(f)
end.

Bye,   Fabio
--
fabio...@rocketmail.com

Re:Text Files


Quote
Jonathan Malcolm wrote in message <7de1hm$o9...@news7.svr.pol.co.uk>...
>Hi,
>    I am learning Pascal at collage. I was wanting help with text files. In
>the text file is a list of email address each on a single line. But what I
>want to do is search the text file for email address with .ac.uk at the
end.
>Any one with a ideas would be very helpful
>    thanks
>    Jonathan

My experience with file handling comes mostly from C, but in this case
Pascal should be no different.  Open the file you want to search as "text".
Read the lines from it one by one with "writeln".

After you've read a line, check its length, and compare the last six
characters with the string ".ac.uk";  if the last six characters are equal
to ".ac.uk" than you've found the line you were looking for. If  you want to
check if the ".ac.uk" string occurs *anywhere* in the e-mail address, not
just at the end, you'll find the Pascal's string handling functions very
handy.  I believe "pos" tells you whether one string occurs in another, and
at what position.  Refer to manual/online help for more info.

Hope this helps.
Nikita.

Other Threads