Solved

Wildcard Function...

Posted on 2004-08-31
7
473 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now