This tutorial explains how to parse multiple instances of an item in one string. Here is the function (which I am actually very proud of):
Code:
function TForm1.MultiParse(MainString, BeginString, EndString: string): TStrings;
var
PosBeginString, PosEndString, i, LastPos: integer;
tmpCopy: string;
tmpStrings: TStrings;
begin
tmpStrings := TStringList.Create;
LastPos := 0;
for i := 1 to LastDelimiter(EndString, MainString) do
begin
PosBeginString := PosEx(BeginString, MainString, LastPos) + Length(BeginString);
PosEndString := PosEx(EndString, MainString, LastPos);
tmpCopy := Copy(MainString, PosBeginString, PosEndString - PosBeginString);
if Length(Trim(tmpCopy)) <> 0 then tmpStrings.Add(tmpCopy);
LastPos := LastPos + PosEndString;
end;
Result := tmpStrings;
end;
Notice how the function returns the parsed data using the data type of TStrings, which is essentially an easier to work with version of a string array.
The code would be used as follows:
Code:
Memo1.Lines.AddStrings(MultiParse('The person named Joe is friendly. The person named Bob is friendly.', 'named ', ' is'));
The strings 'Bob' and 'Joe' will both be contained in the returnd TStrings data type, and will be added to Memo1, whose primary "lines" property is also of the same data type.
Notes:
1) Because of its usage of the PosEx function, to use this function "StrUtils" must be included in the uses section of your unit.
2) The code doesn't necessarily need to be contained in a function. You can adapt it to place in a procedure.
-----------------
Hope some of you find this useful, I may post some more tutorials pertaining to HTML,PHP,C#,DELPHI,MYSQL.....Maybe some other stuff too. Will probably post something soon, as soon as I get time. Thanks for reading lemme know if this helped you by giving me some repuation points.

