function GetStringFromHere(aList: TStringList;
StartIndex, TokenCount: integer):
string;
var
i: integer;
begin
Result := aList[StartIndex];
// Achtung keine Abprüfung auf < 0 oder > aList.Count-1 ...!!
for i := StartIndex+1
to StartIndex+TokenCount-1
do
if (i > aList.Count-1)
then
break
else
Result := Result + aList[i];
end;
function GetMatchIndex(aList: TStringList;
OriginIndex, TokenCount: integer): integer;
var
s:
string;
i: integer;
begin
Result := -1;
s := GetStringFromHere(aList, OriginIndex, TokenCount);
for i := 0
to aList.Count-1
do
if (i <> OriginIndex)
then
if (s = GetStringFromHere(aList, i, TokenCount))
then
begin
Result := i;
break;
end;
end;
function GetAnyMatchIndex(aList: TStringList;
TokenCount: integer): integer;
var
i: integer;
begin
Result := -1;
for i := 0
to aList.Count-1
do
if (GetMatchIndex(aList, i, TokenCount) <> -1)
then
begin
Result := i;
break;
end;
end;
function FindBiggestMatch(aList: TStringList): integer;
var
TokenCount: integer;
MatchIndex: integer;
begin
Result := 0;
TokenCount := Length(aList.Text);
while (TokenCount >= 1)
do
begin
MatchIndex := GetAnyMatchIndex(aList, TokenCount);
if (MatchIndex <> -1)
then
begin
ShowMessage('
Größter Match "' + GetStringFromHere(aList, MatchIndex, TokenCount) +
'
" bei Index ' + IntToStr(MatchIndex) + #13#10 +
'
Anzahl Zeichen: ' + IntToStr(TokenCount));
Result := TokenCount;
break;
end;
dec(TokenCount);
end;
end;