Solved

Wildcard Function...

Posted on 2004-08-31
7
477 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: 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!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi inherited method 6 86
JAudiorecorder record freezing the app 29 89
Microsoft Access 97 and Delphi XE2 9 82
Using MMsystem To change audio input 1 36
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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