Board index » delphi » Help needed ny newbie programmer.

Help needed ny newbie programmer.

Hi,

I am using Delphi V1 which I got off of a magazine cover disc.

The program I am writing takes a text file line by line and strips out the
unwanted characters that are specified in the actual code. The text files
always have the following format -

S700,B,CA1256,LIBRARY,ARCUS
S700,B,CA1532,LIBRARY,ARCUS
etc.

Using the delete(string,1,7) command i can extract and save the info I need
(the CA1256) bit, and the another delete command gets rid of the rest. Here
is the problem, as I am reading each line into a string array there are
serious size limitations to the text file. I need to be able to read in and
change files of about 150k maximum.

Any help would be appreciated. Please remember I am still learning so try
not to be too technical :)

Andy Moore.

 

Re:Help needed ny newbie programmer.


Hi andrew..
Well Dont try and read the whole file at once but proccess the file line by
line.. Readln.. strip what you dont want then Write it to a new file..

maybee something like this..

Procedure ProcessFile;
var
TheLine , TheNewLine:String;
SrcFile,DestFile:TextFile;
   begin
   {open your files make sure the SrcFile exists}
  if Not FileExists('c:\dir\file.txt') then begin
  ShowMessage('File not found);
     exit;    {file not there}
              end;
{open the SrcFile}
 AssignFile(SrcFile,'c:\dir\file.txt');
         reset(SrcFile);
{make the dest file}
   AssignFile(DestFile,'c:\dir\new.txt');
     ReWrite(DestFile);
{Loop thru the src file line by line}
      While not EOF(SrcFile) do begin
   ReadLn(SrcFile,TheLine);
   TheNewLine:=ProccessLine(TheLine);
     Writeln(DestFile,TheNewLine);
            end;{do}
   CloseFile(SrcFile);
      CloseFile(DestFile);
          end;{ProccessFile}

Function ProccessLine(Aline:String):String;
   begin
    {strip what you dont want here}
        end;
 well hope this helps a little..

Dave

Quote
Andrew Moore wrote in message <6u2mrb$6k...@epos.tesco.net>...
>Hi,

>I am using Delphi V1 which I got off of a magazine cover disc.

>The program I am writing takes a text file line by line and strips out the
>unwanted characters that are specified in the actual code. The text files
>always have the following format -

>S700,B,CA1256,LIBRARY,ARCUS
>S700,B,CA1532,LIBRARY,ARCUS
>etc.

>Using the delete(string,1,7) command i can extract and save the info I need
>(the CA1256) bit, and the another delete command gets rid of the rest. Here
>is the problem, as I am reading each line into a string array there are
>serious size limitations to the text file. I need to be able to read in and
>change files of about 150k maximum.

>Any help would be appreciated. Please remember I am still learning so try
>not to be too technical :)

>Andy Moore.

Re:Help needed ny newbie programmer.


Cheers Dave,

this worked, I had thought of having the two files open before but for some
unknown reason, I got into my head that two files could not be open at the
same time. I'm glad you proved this was wrong.

Newbies, eh!

Andy Moore.

Quote
David Meunier wrote in message <6u2um4$...@dfw-ixnews3.ix.netcom.com>...
>Hi andrew..
>Well Dont try and read the whole file at once but proccess the file line by
>line.. Readln.. strip what you dont want then Write it to a new file..

>maybee something like this..

>Procedure ProcessFile;
>var
>TheLine , TheNewLine:String;
>SrcFile,DestFile:TextFile;
>   begin
>   {open your files make sure the SrcFile exists}
>  if Not FileExists('c:\dir\file.txt') then begin
>  ShowMessage('File not found);
>     exit;    {file not there}
>              end;
>{open the SrcFile}
> AssignFile(SrcFile,'c:\dir\file.txt');
>         reset(SrcFile);
>{make the dest file}
>   AssignFile(DestFile,'c:\dir\new.txt');
>     ReWrite(DestFile);
>{Loop thru the src file line by line}
>      While not EOF(SrcFile) do begin
>   ReadLn(SrcFile,TheLine);
>   TheNewLine:=ProccessLine(TheLine);
>     Writeln(DestFile,TheNewLine);
>            end;{do}
>   CloseFile(SrcFile);
>      CloseFile(DestFile);
>          end;{ProccessFile}

>Function ProccessLine(Aline:String):String;
>   begin
>    {strip what you dont want here}
>        end;
> well hope this helps a little..

>Dave
>Andrew Moore wrote in message <6u2mrb$6k...@epos.tesco.net>...
>>Hi,

>>I am using Delphi V1 which I got off of a magazine cover disc.

>>The program I am writing takes a text file line by line and strips out the
>>unwanted characters that are specified in the actual code. The text files
>>always have the following format -

>>S700,B,CA1256,LIBRARY,ARCUS
>>S700,B,CA1532,LIBRARY,ARCUS
>>etc.

>>Using the delete(string,1,7) command i can extract and save the info I
need
>>(the CA1256) bit, and the another delete command gets rid of the rest.
Here
>>is the problem, as I am reading each line into a string array there are
>>serious size limitations to the text file. I need to be able to read in
and
>>change files of about 150k maximum.

>>Any help would be appreciated. Please remember I am still learning so try
>>not to be too technical :)

>>Andy Moore.

Other Threads