Here is my code.
var
filehan : Textfile;
i : Integer;
LineOfText : String;
tsl : TStringList;
Name, Emp_id : string;
begin
stf := TStringList.create;
Assignfile ( filehan, 'EMP.txt');
Reset ( filehand );
While not EOF(filehan) do
begin
inc(i);
ReadLn ( filehan, LineOfText );
tsl :=substrings(LineOfText, ':' );
Name := tsl[1];
Emp_id := tsl[0];
tsl.SaveToFile('FSTRING.txt');
end;
CloseFile (FFile);
end;
function SubStrings(AString: String; ADelimiter: Char): TStringList;
var
sList : TStringList;
curPos : Integer;
subString : String;
{ DelimiterPos : Integer}
begin
curPos := 1;
sList := TStringList.Create;
while (curPos <= Length(AString)) do
begin
subString := '';
While (AString[curPos] <> ADelimiter) and
(curPos <= Length(AString)) do
begin
subString := subString + Copy(AString,curPos,1);
curPos := curPos + 1;
end;
sList.Add(subString);
curPos := curPos + 1;
end;
Result := sList;
end;
The file consist of around 2000 lines. one line looks like this
300: rani : joseph: 210: 500 : 700
If the line has the number 210 at 3rd position,I have to retrieve more details of the employee which is stored in database. How I can do it?
I want to read all the lines in the file.
Thanks for your time.
See Question&Answers more detail:os