如有一个车牌:京A12345用户可能输入:京A12***,京A123**,京A123*5,京A**345 进行模糊查询,总之*的位置不固定。如何对用户输入的模糊车牌进行解析。知道每个*的位置和个数?我好以此为依据对数据库进行搜索。结果能显示*的位置和总个数给出代码,谢谢! 

解决方案 »

  1.   

    利用CString::Find()依次查找,找到字符串中所有的*字符,行不?
      

  2.   

    Find是找到第一个,然后再截取,再找,直到找完为止?
      

  3.   

    int Find(const CString& strText, int* pArray, int nCount)
    {
    if(strText.GetLength() && (NULL != pArray) && nCount)
    {
    memset(pArray, -1, sizeof(int) * nCount); LPCTSTR lpszToken = _T("*");
    int nStart = 0;
    int nEnd = 0;
    int nIndex = 0;
    while(-1 != (nEnd = strText.Find(lpszToken, nStart)))
    {
    pArray[nIndex++] = nEnd;
    nStart = nEnd + _tcslen(lpszToken);
    }
    return nIndex;
    }
    return 0;
    }// 调用
    int a[10] = {0}; int nRet = Find(_T("京A12***"), a, 10);
    CString strText;
    CString strTmp;
    for(int i=0; i != nRet; ++i)
    {
    strTmp.Format(_T("%d,"), a[i]);
    strText += strTmp;
    }
    AfxMessageBox(strText);
      

  4.   

    char[8]="京A123**";
    int xn=0;
    int wn[4]={0};
    for(int x=2;x<8,x++){  if(char[x]==42)
      {
        wn[xn]=1;
        xn++;       }
    }
      

  5.   


    CString strNumber = _T("京A*1*2*3");
    int nPos = 0;
    int nTotal = 0;
    CString strDisplay = _T("");
    while ((nPos=strNumber.Find('*', nPos)) != -1)
    {
    ++nTotal;
    //汉字两个字节
    strDisplay.Format("%d", nPos);
    AfxMessageBox(strDisplay);
    ++nPos;
    }
      

  6.   

    楼上全部pass,SQL语句本来就有这样的功能。http://wenku.baidu.com/view/96268c49cf84b9d528ea7a45.html
      

  7.   

    如果你输出A12***,则这样查询。SELECT * FROM [tablename] WHERE u_chepai LIKE A12%总之还是要根据你输入,转换成SQL的模糊查询。这中间还需要设计一下
      

  8.   

    数据库没学好啊。
    SQL是很强大的。我也忘了。不怎么用到就容易忘~
      

  9.   

    SELECT * FROM TABLENAME 
    WHERE CARNO LIKE '%'+ PARTCARNO +'%'
      

  10.   

    CString s = "京A1*1**";
    s.ReplaceA('*', '?');CString sql;
    sql.Format("select * from tb where fd1 like '%s'", s);
      

  11.   

    不是查找数据库;
    我是想两个车牌模糊比对如下:
    如有一个车牌:京A12345用户可能输入:京A12***,京A123**,京A123*5,京A**345 进行模糊比对,*的位置不固定。我怎么判断 京A12***,京A123**,京A123*5,京A**345等车牌,除了*之外的汉字或者数字都相同,且位置一样。目前我是这样想的,如果车牌X为京A12345,要与Y车牌京A123*5进行对比,我首先把Y车牌京A123*5中的,*位置取出来,然后把X车牌京A12345中同位置的数字4替换成*,然后把替换后的X车牌京A123*5与Y车牌京A123*5比较,是相同的。也就是车牌模糊比对,如果出了*之外的所有数字和汉字都相同,则记录下来。X车牌京A12345不知道我表述的是否清楚呢?
    我用VS2010开发,先前开了一个类似的帖子,其中有人给出的代码在2010下不能编译,郁闷那!!!
      

  12.   

    自己写了一个很笨的方法,请指点:看有什么bug吗?偶尔会报个错,运行异常。
    京A12***,京A123**,京A123*5,京A**345随便输入,最后得出替换掉对应位置的车牌号,然后再跟模糊的进行比较。CString CXXXXtDlg::AnalyseStr(CString alarmHphm,CString Hphm) 
    {
    CString str,strPostion;
    int postion1,postion2,postion3,postion4,postion5;
    int count=alarmHphm.Replace(L"*",L"*");
    if(count>0)
    {
    switch(count)
    {
    case 1:
    postion1=alarmHphm.Find(L"*");
    Hphm.SetAt(postion1,'*');
    break;
    case 2:
    postion1=alarmHphm.Find(L"*");
    Hphm.SetAt(postion1,'*');
    postion2=alarmHphm.Find(L"*",postion1+1);
    Hphm.SetAt(postion2,'*');
    break;
    case 3:
    postion1=alarmHphm.Find(L"*");
    Hphm.SetAt(postion1,'*');
    postion2=alarmHphm.Find(L"*",postion1+1);
    Hphm.SetAt(postion2,'*');
    postion3=alarmHphm.Find(L"*",postion2+1);
    Hphm.SetAt(postion3,'*');
    break;
    case 4:
    postion1=alarmHphm.Find(L"*");
    Hphm.SetAt(postion1,'*');
    postion2=alarmHphm.Find(L"*",postion1+1);
    Hphm.SetAt(postion2,'*');
    postion3=alarmHphm.Find(L"*",postion2+1);
    Hphm.SetAt(postion3,'*');
    postion4=alarmHphm.Find(L"*",postion3+1);
    Hphm.SetAt(postion4,'*');
    break;
    case 5:
    postion1=alarmHphm.Find(L"*");
    Hphm.SetAt(postion1,'*');
    postion2=alarmHphm.Find(L"*",postion1+1);
    Hphm.SetAt(postion2,'*');
    postion3=alarmHphm.Find(L"*",postion2+1);
    Hphm.SetAt(postion3,'*');
    postion4=alarmHphm.Find(L"*",postion3+1);
    Hphm.SetAt(postion4,'*');
    postion5=alarmHphm.Find(L"*",postion4+1);
    Hphm.SetAt(postion5,'*');
    break;
    default:
    break;
    }
    }
    return Hphm;
    }调用
    CString hphm=AnalyseStr("京P12**5","京P12345");
    返回hphm="京P12**5";
      

  13.   

    没人提出意见啊?我得出返回值hphm="京P12**5";
    与另外一个车牌hphm2 =京P12**5进行比较,
    if(hphm==hphm2)
    {afxmessagebox("找到车牌");
    }else{afxmessagebox(放弃"");}
      

  14.   

    CString CXXXXtDlg::AnalyseStr(CString alarmHphm,CString Hphm)  
    {
       int iLen = alarmHphm.GetLength();
       if(iLen != Hphm.GetLength()) return "";//长度不等
       for(int i=0;i<iLen;i++)
       {
          if(alarmHphm.GetAt(i) == '*') continue;
          if(alarmHphm.GetAt(i) != Hphm.GetAt(i)) return "";//不匹配
       }
       return Hphm;//匹配
    }}