|
|
|
Navigation
0 users online | 0 Guests and 0 Registered
|
Delphi » StringsID #1071
Verschieden Beispiele für die Funktion POSMit der Funktion After() extrahierst du den Teil eines Strings, der einem bestimmten Teilstring folgt.
uses
StrUtils; // PosEx(), AnsiContainsText()
function After(const s, subStr: String): String;
var
i: Integer;
begin
i := Pos(subStr, s);
if i = 0 then
Result := ''
else
Result := Copy(s, i + Length(subStr), MaxInt);
end;
function Between(const s, sLeft, sRight: String): String;
var
iLeft, iRight: Integer;
begin
iLeft := Pos(sLeft, s);
if iLeft > 0 then
begin
Inc(iLeft, Length(sLeft));
iRight := PosEx(sRight, s, iLeft);
if iRight > 0 then
Result := Copy(s, iLeft, iRight - iLeft)
else
Result := '';
end
else
Result := '';
end;
procedure CustomExtract(sIn, sOut: TStrings; const keyword: String);
var
i: Integer;
s: String;
begin
sOut.Clear;
for i := 0 to Pred(sIn.Count) do
begin
s := Between(sIn[i], '(', ')');
if s <> '' then
begin
if AnsiContainsText(After(sIn[i], ')'), keyword) then
s := s + ' ' + keyword;
sOut.Add(s);
end;
end;
end;
procedure TDemoForm.ButtonClick(Sender: TObject);
begin
CustomExtract(Memo.Lines, ListBox.Items, 'Konto');
end;
Dieser Beitrag aus dem Forum Delphi-Praxis diente als Grundlage. Tags: - Related entries: - Last update: 2010-08-28 10:14 You can comment this FAQ |
Most popular FAQs
|