Hvordan kan man søge i en fil og tælle hvor mange linjer der er som starter
med et ord f.eks. 6 tegn inde.Og filen skal tjekkes uden at være open i
en editor.
MVH.
Computerfreack.
http://www.friserverplads.dk/computerfreack
Tjaa, dette her virker.
program FileTest;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
myFile : TextFile;
myToken : string;
myFileName : string;
currentLine : string;
begin
myFileName := 'aFile.txt';
myToken := 'myWord';
{Assigning the file myFileName to the handle myFile.}
AssignFile(myFile, myFileName);
{Opening the file for reading.}
Reset(myFile);
{We continue to do the whatever until the whole file has been read.}
While not Eof(myFile) do
begin
{Reading a line from the file.}
ReadLn(myFile, currentLine);
{Strings can be indexed like arrays. And all the usually array functions and procedures can be used on strings.}
if myToken = copy(currentLine, 6, Length(myToken)) Then WriteLn(currentLine);
end;
{Closing the file. This will save the new contents, and free the filehandle myFile.}
CloseFile(myFile);
end.
Mvh.,
Jakob Justsen