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

C / C++ / MFC

 
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 
GeneralRE: RE: RE: wildcard matching with strings Pin
Serguei Velikevitch3-Dec-99 4:07
sussSerguei Velikevitch3-Dec-99 4:07 
Hi Thomas,

Try this method, maybe it will work correctly:

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

char *p;
if ((p = strpbrk(lpszWildCard, "?*")) == NULL)
return 0 == strcmp(lpszWildCard, lpszString);

if (0 != strncmp(lpszString, lpszWildCard, p - lpszWildCard))
return false;

lpszString += p - lpszWildCard;
if (*p == '?')
return (*lpszString != NULL) && my_strmatch(++p, ++lpszString);

while (true)
{
while (*p == '*') ++p;
if (*p == NULL)
return true;
if (*p != '?') break;
++lpszString;
++p;
}

while (true)
{
if ((lpszString = strchr(lpszString, *p)) == NULL)
return false;

if (*lpszString == NULL)
return false;

if (my_strmatch(p + 1, ++lpszString))
return true;
}

return false;
}

Regards,
Serguei Velikevitch,
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: 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 
QuestionHow to change the default value of a DAO field object Pin
Joep30-Nov-99 3:06
Joep30-Nov-99 3:06 

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.