Solved

Wildcard Function...

Posted on 2004-08-31
7
472 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

10 Experts available now in Live!

Get 1:1 Help Now