小弟想请教各位有什么高招
DWORD timesInStr(CString str1,CString str2)
{
    DWORD dwReturn;
    ///////////////////////////////////
    //add code here...
    
    return dwReturn;
}

解决方案 »

  1.   

    DWORD timesInStr(CString str1,CString str2)
    {
        DWORD dwReturn = 0;
        ///////////////////////////////////
        //add code here...
        while(str1.Find(str2))
         {
             dwReturn++;
             str1.Delete(str1.Find(str2), str2.GetLenth());
         }
        return dwReturn;
    }
      

  2.   

    DWORD timesInStr(CString str1,CString str2)
    {
        DWORD dwReturn = 0;
        ///////////////////////////////////
        //add code here...
        while(str1.Find(str2))
         {
             dwReturn++;
             str1.Delete(str1.Find(str2), str2.GetLenth());
         }
        return dwReturn;
    }
      

  3.   

    好像最快的就是 KMP 算法了?
      

  4.   

    liugy(光哥 没有做不到 只有想不到) ,你的算法可能是效率最低的一种了。
    Find 就效率很低,而 Delete 的效率更低!
      

  5.   

    还有一点需说明的是
    str1(需要在其中查找的)比较大