例如*abc?k
123abc9k(满足要求)在网上也找到了一些例程,大多逻辑复杂,完全没有优雅二字.我又想偷懒,请高手成全,谢谢!(粘上代码才给分)

解决方案 »

  1.   

    贴一段以前的代码,优雅说不上,功能能实现。//// 分解字符串
    void prsString(CString str, CString & strTemp1, CString & strTemp2)
    {
    CString strTemp = str.SpanIncluding("*?");
    strTemp = str.Mid(strTemp.GetLength()); strTemp1 = strTemp.SpanExcluding("*?");
    strTemp2 = strTemp.Mid(strTemp1.GetLength());
    }//// 比较字符串strS和带有通配符的字符串str
    BOOL compare(CString str, CString strS)
    {
    BOOL bRetVal = 0;
    int nPos;
    CString strTemp,strTemp2,strSTemp,strSTemp2; if (str.IsEmpty() && strS.IsEmpty())
    return TRUE;

    if (str.Find('?') == 0)
    {
    bRetVal = compare(str.Mid(1), strS.Mid(1));
    if (!bRetVal)
    {
    return FALSE;
    }
    else
    return TRUE;
    }

    if (str.Find('*') == 0)
    {
    strSTemp = strS;
    prsString(str, strTemp, strTemp2); while((strSTemp.GetLength() > 0))
    {
    nPos = strSTemp.Find(strTemp); if (-1 == nPos)
    {
    return FALSE;
    }
    strSTemp2 = strSTemp.Mid(nPos + strTemp.GetLength());
    if (strTemp2.IsEmpty() && strSTemp2.IsEmpty())
    {
    return TRUE;
    } bRetVal = compare(strTemp2, strSTemp2);
    if (bRetVal)
    {
    return TRUE;
    }
    strSTemp = strSTemp.Mid(nPos + 1);
    }
    return FALSE;
    } prsString(str, strTemp, strTemp2); if (strTemp2.IsEmpty())
    {
    bRetVal = strS.Compare(strTemp);
    if (bRetVal || (strS.GetLength() != str.GetLength()))
    {
    return FALSE;
    }
    else
    return TRUE;
    } strSTemp = strS.Left(strTemp.GetLength());
    if (strSTemp.Compare(strTemp))
    {
    return FALSE;
    } strSTemp = strS.Mid(strSTemp.GetLength());
    bRetVal = compare(strTemp2, strSTemp); return bRetVal;
    }
      

  2.   

    可以看看<<程序设计实践>>那本书,后面有个章节提供了一个实现.用递归.
    网上可以下载这个书的电子版本