Solved

Wildcard Function...

Posted on 2004-08-31
7
475 Views
Last Modified: 2010-04-05
Hello,
I need a wildcard function.

This is what it needs to beable to do.

Wildcard('MyString', '*String') = True
Wildcard('MyString', '*Str*') = True
Wildcard('MyString', 'My*') = True
Wildcard('MyString', 'Str*') = False

Thanks.
0
Comment
Question by:GreenNewt
7 Comments
 
LVL 4

Expert Comment

by:tobjectpascal
ID: 11941989
I was always led to believe that this was a fourm for people who got stuck because they could not get their code to work or needed a starting point, not for someone to say i need a function to do "This" or "That" i do believe www.rentacoder.com does that or am i totally mistaken?

Have you attempted to write this routine yourself? after all experts-exchange would imply that you also help others if and when you can.
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11942067
I believe Delphi 7 has a 'like' function somewhere in the strings unit, which does something similar. Am not using Delphi 7 right now so I'm not sure. I know more in 8 hours, I hope, when I'm back home and behind my computer. :)
0
 

Author Comment

by:GreenNewt
ID: 11942106
Ok, Thanks for reply.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 20

Accepted Solution

by:
Madshi earned 250 total points
ID: 11942165
http://help.madshi.net/StringCompare.htm#StrMatch

This part of my collection ("madBasic") is freeware and comes with full sources.
0
 

Author Comment

by:GreenNewt
ID: 11942197
Thank you, I will take a look. ;)
0
 

Author Comment

by:GreenNewt
ID: 11942328
Thanks Madshi
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 11942397
unit main;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    inpStr: TEdit;
    Label2: TLabel;
    inpFind: TEdit;
    btnCheck: TButton;
    procedure btnCheckClick(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses StrUtils;

function Wildcard(Str, FindStr: string): boolean;
type TFindOption = (foStartsWith, foEndsWith, foContains);
var FindOption: TFindOption;
begin
  //by default i.e. when str starts and ends with * or even when no * are used
  FindOption:= foContains;

  //remove leading and trailing spaces
  Trim(Str);
  Trim(FindStr);

  if FindStr[1] = '*' then FindOption:= foEndsWith;
  if FindStr[Length(FindStr)] = '*' then
    if FindOption <> foEndsWith
      then FindOption:= foStartsWith
      else FindOption:= foContains;

  FindStr:= StringReplace(FindStr,'*','',[rfReplaceAll]);

  case FindOption of
    foStartsWith: result:= (FindStr = LeftStr(Str,Length(FindStr)));
    foEndsWith  : result:= (FindStr = RightStr(Str,Length(FindStr)));
    foContains  : result:= (Pos(FindStr,Str)<> 0);
  end;
end;

procedure TForm1.btnCheckClick(Sender: TObject);
begin
  if WildCard(inpStr.Text, inpFind.Text)
    then ShowMessage('Found')
    else  ShowMessage('Not Found');
end;

end.
~~~~~~~~
DFM File
object Form1: TForm1
  Left = 192
  Top = 114
  Width = 233
  Height = 166
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 16
    Top = 16
    Width = 27
    Height = 13
    Caption = 'String'
  end
  object Label2: TLabel
    Left = 16
    Top = 48
    Width = 20
    Height = 13
    Caption = 'Find'
  end
  object inpStr: TEdit
    Left = 72
    Top = 16
    Width = 121
    Height = 21
    TabOrder = 0
  end
  object inpFind: TEdit
    Left = 72
    Top = 48
    Width = 121
    Height = 21
    TabOrder = 1
  end
  object btnCheck: TButton
    Left = 72
    Top = 88
    Width = 75
    Height = 25
    Caption = 'Check'
    TabOrder = 2
    OnClick = btnCheckClick
  end
end
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to center only a line in richedit? 4 61
find a node in VST 2 73
PHP preg_replace code convert to Delphi 14 67
RESTRequest Parameter 4 43
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question