function TForm1.ExtractString(const aString: string; const aSeparator: char; var aPos: Integer): string;
var
I: Integer;
begin
I := aPos;
while (I <= Length(aString)) and (aString[I] <> aSeparator) do Inc(I);
Result := Trim(Copy(aString, aPos, I - aPos));
if (I <= Length(aString)) and (aString[I] = aSeparator) then Inc(I);
aPos := I;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
lString, lSubString: string;
lPos, j: integer;
begin
lString := '023842394201342|343242423423|342342424|533423|2455';
lPos := 1;
j := 0;
while lPos <= Length(lString) do
begin
lSubString := ExtractString(lString, '|', lPos);
inc(j);
if j = 2 then // 第二個
showmessage(lSubString);
end;
end;