Click here to Skip to main content
15,920,102 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRE: Question about dll Pin
Alex Gorev6-Dec-99 7:10
Alex Gorev6-Dec-99 7:10 
QuestionHow to make StatusBar tooltips? Pin
Stefan3-Dec-99 8:21
Stefan3-Dec-99 8:21 
AnswerRE: How to make StatusBar tooltips? Pin
Member 3646-Dec-99 6:47
Member 3646-Dec-99 6:47 
AnswerRE: How to make StatusBar tooltips? Pin
ac2718-Dec-99 4:07
sussac2718-Dec-99 4:07 
Generalwildcard matching with strings Pin
Thomas2-Dec-99 6:34
Thomas2-Dec-99 6:34 
GeneralRE: wildcard matching with strings Pin
Alex Gorev2-Dec-99 8:35
Alex Gorev2-Dec-99 8:35 
GeneralRE: RE: wildcard matching with strings Pin
Thomas3-Dec-99 0:19
Thomas3-Dec-99 0:19 
GeneralRE: RE: RE: wildcard matching with strings Pin
Alex Gorev3-Dec-99 3:31
Alex Gorev3-Dec-99 3:31 
Hi Thomas!

Of course my example will not work correctly in many situations,
I've spend about 5 minutes writing it and my main task was to give
an idea how you can do this.

If you really want to make something like this you should spend much
more time coding and testing. You've mention about the recursion but
I don't think it's the right place for it, the only place when you can use
it
is while testing for the '*' but I don't see big advantage comparing to the
usual loop.

So spend some time, add several IFs and WHILEs and it will work great
for you. And don't try to find an existing function, it's always better to
do something small like this yourself, because you can always adjust it
to your own needs.

Don't forget to post the results on the CodeProject and I will also took
part in testing...

Regards,
Alex Gorev,
Dundas Software.
==================
The original message was:

Hi Alex,

thanks for your code. It is ok for the most cases. But there are many cases in which strmatch() will fail:

strmatch("*?s*", "doesmatch");
doesn't work, because after '*' explicit match to '?' is searched.

strmatch("*to*", "doesmatchtoo");
doesn't work because '*t' finds the first 't' and compares "tchtoo" with "to*" - result: no match.

Due to a bug in the '*' case, the function will return false on all wildcards, that end on '*':

else if(*lpszWildCard == '*')
{
++ lpszWildCard;
while(*lpszWildCard!=*lpszString && *lpszString!=NULL)
{
++lpszString;
// this is WRONG
//if(*lpszWildCard == NULL || *lpszString == NULL)
// break;
// must be like this:
if(*lpszWildCard == NULL)
return TRUE; // rest DOES match to '*'!
if (*lpszString == NULL)
break;
}
}

I suppose, that a 100% solution requires recursion and is NOT so easy to realize!

-- Thomas
==================
The original message was:

Hi

I don't know any existing function which can
do this but it's very easy to write it yourself.

Here is the fully working example:

bool strmatch(char *lpszWildCard, char *lpszString)
{
if(lpszWildCard == NULL || lpszString == NULL) {
return false;
}

while(*lpszWildCard != NULL && *lpszString != NULL) {
if(*lpszWildCard == '?') {
}
else if(*lpszWildCard == '*') {
++ lpszWildCard;
while(*lpszWildCard != *lpszString && *lpszString != NULL) {
++lpszString;
if(*lpszWildCard == NULL || *lpszString == NULL)
break;
}
}
else if(*lpszWildCard != *lpszString) {
return false;
}

++ lpszString;
++ lpszWildCard;
}

if(*lpszString == NULL) {
while(*lpszWildCard == '*') {
++lpszWildCard;
}
}

if(*lpszWildCard == *lpszString) {
return true;
}

return false;
}

Let me know if you have any problems with this code.

Alex Gorev,
Dundas Software.


==================
The original message was:

Hi,
does anyone know how to to fnd out whether a string matches a wildcard pattern? Something like
int iMatch = wcmatch("??ES*H", "DOESMATCH");
There are lots of functions that use wildcards on filenames or database tables - but I didn' find anything for strings.
Any ideas or sample code welcome!
GeneralRE: RE: RE: wildcard matching with strings Pin
Serguei Velikevitch3-Dec-99 4:07
sussSerguei Velikevitch3-Dec-99 4:07 
GeneralRE: wildcard matching with strings Pin
Member 4043-Dec-99 4:48
Member 4043-Dec-99 4:48 
GeneralRE: wildcard matching with strings Pin
Thomas3-Dec-99 12:32
Thomas3-Dec-99 12:32 
Generalmoving caret in CEditView Pin
hhuynh011-Dec-99 10:27
hhuynh011-Dec-99 10:27 
GeneralRE: moving caret in CEditView Pin
rkm1-Dec-99 14:31
rkm1-Dec-99 14:31 
GeneralRE: moving caret in CEditView Pin
Dean Edmonds8-Dec-99 13:53
sussDean Edmonds8-Dec-99 13:53 
QuestionMemory Leak ??? Pin
Anonymous1-Dec-99 5:42
suss Anonymous1-Dec-99 5:42 
AnswerRE: Memory Leak ??? Pin
John M. Drescher5-Dec-99 4:51
John M. Drescher5-Dec-99 4:51 
Generalnetwork monitor 2.0 SDK Pin
Anonymous1-Dec-99 4:20
suss Anonymous1-Dec-99 4:20 
GeneralDB grid control problem Pin
shahzad30-Nov-99 5:30
shahzad30-Nov-99 5:30 
QuestionWhat do I get back from OLEFormatPtr::GetObject() ? Pin
postgress@hotmail.com30-Nov-99 3:47
susspostgress@hotmail.com30-Nov-99 3:47 
GeneralBeginer ques on programmng practice Pin
Anonymous30-Nov-99 3:31
suss Anonymous30-Nov-99 3:31 
GeneralRE: Beginer ques on programmng practice Pin
Jesse Ezell14-Dec-99 14:56
Jesse Ezell14-Dec-99 14:56 
GeneralRe: Beginer ques on programmng practice Pin
Tomb28-Jun-00 11:10
Tomb28-Jun-00 11:10 
QuestionHow to close the current program and starting another on exit Pin
Joep30-Nov-99 3:11
Joep30-Nov-99 3:11 
AnswerRE: How to close the current program and starting another on exit Pin
Henk Devos30-Nov-99 7:29
Henk Devos30-Nov-99 7:29 
GeneralRE: RE: How to close the current program and starting another on exit Pin
Joep Oude Veldhuis30-Nov-99 12:52
sussJoep Oude Veldhuis30-Nov-99 12:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.