Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

String comparison

well i need some function, wich could compare two strings.

but i do not need to know, if they are equal, but if they are similar by using asterisk convention.

for example: string *abc is similar, but not equal to dabc.

is any api for it? i mean when windows are searching for a file like 'wi*.com', it will find 'win.com' and much more files with similar name. there should be any api, else it would be so relatively quickly.
0
pistacer
Asked:
pistacer
  • 4
  • 2
  • 2
  • +1
1 Solution
 
dMaCommented:
API
int CompareString(
    LCID Locale,     // locale identifier
    DWORD dwCmpFlags,     // comparison-style options
    LPCTSTR lpString1,     // pointer to first string
    int cchCount1,     // size, in bytes or characters, of first string
    LPCTSTR lpString2,     // pointer to second string
    int cchCount2      // size, in bytes or characters, of second string  
   );    
 
but it's not doing exactly what your are needed ..... or?
0
 
pistacerAuthor Commented:
well, from the help i do not know ... i mean i need fction, wich would say:
yes, '*abc' is similar to 'dabc'
and yes, '*abc' is similar to 'bbbabc'
0
 
pistacerAuthor Commented:
well, from the help i do not know ... i mean i need fction, wich would say:
yes, '*abc' is similar to 'dabc'
and yes, '*abc' is similar to 'bbbabc'
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
JaccoCommented:
You need something like regexp.

Regards Jacco
0
 
pistacerAuthor Commented:
wow, and what is it 'regexp' please?
0
 
dMaCommented:
regexp = regular expression notation
0
 
geobulCommented:
Hi,
---
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses Masks;

function StringMatch(const Value, Mask: string): boolean;
var
  oMask: TMask;
begin
  oMask := TMask.Create(Mask);
  try
    result := oMask.Matches(Value);
  finally
    oMask.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if StringMatch(Edit1.Text,Edit2.Text) then ShowMessage('Match')
    else ShowMessage('Do not match');
end;

end.
---

Edit1 is the string to be verified (ex:dddabc) and Edit2 is the mask (ex:*abc).

Regards, Geo
0
 
pistacerAuthor Commented:
bingo!

simple and effective!

thanks wery much!!
0
 
geobulCommented:
You are welcome

Regards, Geo
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now