Hola.
No dispongo del método
Match y no pude hacer comparativas, pero fijate si obtenes alguna mejora de este modo:
Código Delphi
[-]
function ExistsWord(wd: string; Text: string; Separators: array of Char;
const CaseSensitive: Boolean = True): Boolean;
var
SEP : set of Char;
c1,c2,l : Integer;
begin
SEP := [];
for c1 := Low(Separators) to High(Separators) do SEP := SEP + [Separators[c1]];
if not CaseSensitive then
begin
wd := UpperCase(wd);
Text := UpperCase(Text);
end;
Text := Separators[Low(Separators)] + Text + Separators[Low(Separators)];
Result := False;
c1 := 1;
c2 := 1;
l := Length(wd);
while not Result and ( c1 < Length(Text) ) do
begin
if Text[c1] <> wd[c2] then
c2 := 1
else if c2 < l then Inc( c2 );
if c2 = l then
Result := ( Text[c1 - l] in SEP) and (Text[c1 + 1] in SEP);
Inc(c1);
end;
end;
Un ejemplo de uso:
Código Delphi
[-]
procedure TForm1.Button1Click(Sender: TObject);
const
FLG = MB_YESNO + MB_ICONQUESTION;
var
TS: TStrings;
fName,Wd: string;
begin
Wd := 'oso';
fName := 'ARCHIVO.TXT';
TS := TStringList.Create;
try
TS.LoadFromFile( fName );
if MessageBox( 0,'Archivo cargado, ¿ Comienzo la búsqueda ?','', FLG ) = IDYES then
if ExistsWord( wd, TS.Text, [' ',',',';',':',#10,#13] ) then
ShowMessage( 'Palabra encontrada' )
else
ShowMessage( 'Palabra no encontrada' );
finally
TS.Free;
end;
end;
Saludos