Delphi/CB
•  Greatis •  Security •  AppDatabase •  Utilities •  Visual Basic • .NET •  just4fun
Delphi / C++ Builder
Components, utilities and tips for Delphi and C++ Builder developers
Hot Offer
Save your money!
Featured
Ultimate Pack  hot!
Image Editor  new!
Runtime Fusion
Form Designer
Object Inspector
Print Suite Pro
Commented Image
Delphi Toys
WinDowse
Delphi Bonus
TMS Scripter Studio
Form Designer VB
Form Designer .NET

...get more...
for Delphi.NET, C#, VB.NET
for Delphi VCL, BCB 3-6

News Tips .NET Software VCL Software Partners  

Compare string with pattern
If you want to check your string with pattern, which has '?' symbol for changing any symbol, then you may use ComparePattern procedure. First parameter - is a mask, second - is your string and Check variable is result. Result is True, if your string matches with pattern.

procedure ComparePattern(St1, St2: string; var Check: Boolean);
var
  Hlp1, Hlp2: string;
  Pos1: Integer;
begin
  Check:=True;
  while Length(St1)>0 do
  begin
    Pos1:=Pos('?', St1);

    if (Pos1=0) then
    begin
      if CompareStr(St1, St2)<>0 then Check:=False;
      Delete(St1, 1, Length(St1));
      Delete(St2, 1, Length(St2));
    end;

    if (Pos1>0) then
    begin
      Hlp1:=Copy(St1,1,Pos1-1);
      Hlp2:=Copy(St2,1,Pos1-1);
      if CompareStr(Hlp1, Hlp2)<>0 then Check:=False;
      Delete(St1,1,Pos1);
      if Pos1>Length(St2) then Check:=False;
      Delete(St2,1,Pos1);
    end;

    if Check=False then Break;

  end;
  if CompareStr(St1, St2)<>0 then Check:=False;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Check: Boolean;
begin
  ComparePattern(Edit1.text, Edit2.Text, Check);
  if Check=True then Caption:='OK'
  else Caption:='Not OK';
end;

Related topics
Comparing of two strings

For more
Delphi Help

Download source


Our Partner
DevArchive.com
Recommended
just4fun
Useful Resources
Win32.hlp Online
Unix Manual Pages
MegaDetailed.NET
in3steps.com
Newsletters
Subscribe to our news!    Subscribe to our news!


Greatis Software Greatis | Security | AppDatabase | Utilities | Delphi/CB | Visual Basic | .NET | just4fun

Contacts | Add to Favorites | Recommend to a Friend | Privacy Policy | Copyright © 1998-2008 Greatis Software