Wenn ich mich nicht verdacht hab und für ohne RichEdit...
Delphi-Quellcode:
uses
StrUtils, Character;
type
TPosExMode = set of (pemCaseInsensitive, pemWholeWord);
function PosEx2(SubStr, S: string; Offset: Integer = 1; SerarchMode: TPosExMode = []): Integer; overload;
function PosEx2(SubStr, S: AnsiString; Offset: Integer = 1; SerarchMode: TPosExMode = []): Integer; overload;
function PosEx2(SubStr, S: string; Offset: Integer; SerarchMode: TPosExMode): Integer;
begin
if pemCaseInsensitive in SerarchMode then begin
SubStr := AnsiUpperCase(SubStr);
S := AnsiUpperCase(S);
end;
Result := Offset - 1;
repeat
Result := PosEx(SubStr, S, Result + 1);
until (Result = 0) or not (pemWholeWord in SerarchMode) or (((Result = 0) or not IsLetterOrDigit(S[Result - 1]))
and ((Result + Length(SubStr) > Length(S)) or not IsLetterOrDigit(S[Result + Length(SubStr)])));
end;
function PosEx2(SubStr, S: AnsiString; Offset: Integer; SerarchMode: TPosExMode): Integer;
const
WordChars: TSysCharSet = ['a'..'z', 'A'..'Z', '0'..'9'];
begin
if pemCaseInsensitive in SerarchMode then begin
SubStr := AnsiUpperCase(SubStr);
S := AnsiUpperCase(S);
end;
Result := Offset - 1;
repeat
Result := PosEx(SubStr, S, Result + 1);
until (Result = 0) or not (pemWholeWord in SerarchMode) or (((Result = 0) or not (S[Result - 1] in WordChars))
and ((Result + Length(SubStr) > Length(S)) or not (S[Result + Length(SubStr)] in WordChars)));
end;
// Beitrag zitieren und dort den Code rauskopieren ... hier ist die Codeformatierung häßlich.
Beim RichEdit pass aber auf, daß FindText den Index für SelStart, SelLength und RichEdit.Text liefert.
Zu RichEdit.Lines.Text paßt dieser Index nicht mehr, daß RichEdit neuerdings einen anderen Zeilenumbruch verwendet. (die Mac #13)