MyArray: array of string; // notice that i dont give a fixed length as i dont know how many records itll have that correspond with my search, make this a global array so it can be accessed from anywhere, I suggest you put it under the private heading
procedure Form1.GetRequiredLines(Sender: TObject);
var i,j: integer; // Loop counters
TestStr: string; // Variable i use to find the right strings and put them into an array
begin
for i := 0 to (Memo1.Lines.Count - 1) do
begin
TestStr := Memo.Lines.String[i];
if SubString(TestStr,1,11) = '33382190495' then
begin
SetLength(MyArray,Length(MyArray)+1);
MyArray[Length(MyArray) - 1] := TestStr;
end;
end;
GetDataFromArray;
end;
// So the procedure above will get the lines from the file.
// The procedure below will get the data from the lines.
procedure Form1.GetDataFromArray;
var i: integer;
StartStr: string; // Get string out of array to work with
Date, Surname, Amount: String; // The variables in the line
begin
// So as I said earlier you could use a loop within a loop to get all the data in a usable form, so let's start with that.
for i := 0 to Length(MyArray) do
begin
StartStr := MyArray[i];
// apperantly you only use that number the line starts with to find the right lines so you can start by deleting that from your string
Delete(StartStr,1,11);
TrimLeft(StartStr); // Removes excess spaces on the left side of the string
for j := 1 to Length(StartStr) do
if StartStr[j] = ' ' then
begin
Date := SubString(StartStr,1,j); // Gets the date
Delete(StartStr,1,j); // Deletes date from StartStr
Break; // Stops this loop
end;
TrimLeft(StartStr);
// Now we come to the DEPOSIT area of the string we'll just delete that from the string
for j := 1 to Length(StartStr) do
if StartStr[j] = ' ' then
begin
Delete(StartStr,1,j); // Deletes DEPOSIT
TrimLeft(StartStr);
Break;
end;
// Now we should encounter the dash '-', lets get rid of that too.
if SubString(StartStr,1,1) = '-' then
Delete(StartStr,1,1);
trimLeft(StartStr);
// ER, apperantly not useful, delete it
Delete(StartStr,1,2);
TrimLeft(StartStr);
// The Surname area
for j := 1 to Length(StartStr) do
if StartStr[j] = ' ' then
begin
Surname := SubString(StartStr,1,j);
Delete(StartStr,1,j);
Break;
end;
TrimLeft(StartStr);
// Those 8 characters are up now
Delete(StartStr,1,8);
TrimLeft(StartStr);
// The Amount area
for j := 1 to Length(StartStr) do
if StartStr[j] = ' ' then
begin
Amount := SubString(StartStr,1,j);
Delete(StartStr,1,j);
Break;
end;
end;
end;