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

C / C++ / MFC

 
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 
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 
Hello everybody and thanks for all tips and code.
After all I wrote my own function that serves my needs.
It is capable to handle ? and * correctly - as I think.
Here it is:

int wcmatch(const char *pPattern, const char *pStr;
const char *mystrstr(const char *pPattern, const char *pStr, int *pLen;



//similiar to strstr() but:
// + the search pattern ends at a '\0' or a '*'.
// + '?' matches to every character != '\0'
// + Return value is pointer to the first char in pStr
// that belongs to the first occurence of pPattern
// or NULL if not found.
//
// Example: mystrstr("a?c*xyz", "123456abcdefg", &len) = "abcdefg"
// len==3.
const char *mystrstr(const char *pPattern, const char *pStr, int *pLen)
{
int iMatch;

const char *pStart=pStr, *pp, *ps;

if (pLen)
*pLen = 0;

if (!pPattern || !pStr)
return FALSE;

for (pStart=pStr; *pStart; pStart++)
{
ps = pStart;
pp = pPattern;
iMatch = TRUE;
while (iMatch)
{
switch (*pp)
{
case '*':
case '\0':
if (pLen)
*pLen = ps - pStart;
return pStart;
break;

case '?':
if (*ps)
{
pp++; ps++;
}
else
iMatch = FALSE;
break;

default:
if (*pp == *ps)
{
pp++; ps++;
}
else
iMatch = FALSE;
break;
}
}
}
return FALSE;
}

int wcmatch(const char *pPattern, const char *pStr)
{
if (!pPattern || !pStr)
return FALSE;

int iWildcardMode = FALSE,
iLen;
const char *pStarMatchStart;

while (*pPattern && *pStr)
{
switch (*pPattern)
{
case '?':
pPattern++; pStr++;
break;

case '*':
// Switch to wildcard-mode. Keep this mode until a
// character diffrent to '?' and '*' is found.
iWildcardMode = TRUE;
pPattern++;
break;

default:
if (iWildcardMode)
{
iWildcardMode = FALSE;
if (pStarMatchStart = mystrstr(pPattern, pStr, &iLen))
{
pPattern += iLen;
pStr = pStarMatchStart + iLen;
}
else
return FALSE;
}
else
{
if (*pPattern != *pStr)
return FALSE;
pPattern++; pStr++;
}
break;
}
}

if (*pPattern == *pStr)
return TRUE;

if (*pPattern == '\0')
{
if (iWildcardMode)
return TRUE; // Last char of pattern was '*'
else
return FALSE; // String has additional non matching chars. No match.
}
if (*pStr=='\0')
{
// This is a match, if only '*'s follow
while (*pPattern == '*')
pPattern++;
if (*pPattern != '\0')
return FALSE; // Pattern has additional non matching chars. No match.
}

return TRUE;
}



==================
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!
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 
AnswerRE: How to change the default value of a DAO field object Pin
Anonymous3-Dec-99 3:18
suss Anonymous3-Dec-99 3:18 
GeneralPrint a dialog box! Pin
sandrine29-Nov-99 22:56
sandrine29-Nov-99 22:56 

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.