program StringLike1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, Masks, SysUtils, crt
{ you can add units after this };
{$R *.res}
var
ch:char;
function StringLike(const str: string; mask: string): boolean;
{Utility for VB style string comparison. The pattern of comparison is
"mask" and has the following wildcards:
'?' -> matches any character.
'*' -> matches any text.
'#' -> matches any numeric character.
'[]' -> indicates a set of cacacters.
}
var
msk: TMask;
begin
mask := StringReplace(mask, '#', '[0-9]', [rfReplaceAll]);
try
msk := Tmask.Create(mask);
except
on E: Exception do
writeln('ERROR 1: ',E.Message);
end;
try
Result := msk.Matches(str);
except
on E: Exception do
writeln('ERROR 2: ',E.Message);
end;
try
msk.Destroy;
except
on E: Exception do
writeln('ERROR 3: ',E.Message);
end;
end;
procedure Test0(pStr,pMsk:string);
begin
writeln(pStr,' ',pMsk,' ',StringLike(pStr,pMsk));
end;
procedure Test1;
begin
Test0('N 10 32 29 W 47 4 21','[N,S,E,W]?[0-9]*[N,S,E,W]?[0-9]*');
Test0('N 10 32 29 W 47 4 21','[N,S,E,W]?[0-9]*');
ch:=readkey;
if ch=#27 then writeln;
end;
begin
Test1;
end.