CString __stdcall GetValueByKey(const char *key,const char *scr,char *outstr ) 

   //按我的需求请写出这里的代码
   //这两个参数: key = QQ, scr = <&QQ&>123456</&QQ&>, 那么outstr输出就是123456,就是说用正则或字符串处理的方式用key去匹配scr里的数据,最终将得到的值赋outstr

解决方案 »

  1.   

    LZ还是看看MSXML吧,可能适合你
      

  2.   

    char cOutStr[1024];
    GetValueByKey("QQ","<&QQ&>1234567<&QQ&>",cOutStr);
    AfxMessageBox(cOutStr);CString GetValueByKey(const char *key, const char *scr, char *outstr)
    {
    CString strTempKey;
    CString strTempScr;
    CString strTempOutStr;
    strTempKey.Format("<&%s&>",key);
    strTempScr.Format("%s",scr);
    int nStartPos = strTempScr.Find(strTempKey,0);
    int nEndPos   = strTempScr.Find(strTempKey,nStartPos+1);
    strTempOutStr = strTempScr.Mid(nStartPos + strTempKey.GetLength(),nEndPos-nStartPos -        strTempKey.GetLength());
    strcpy(outstr,strTempOutStr);
            return strTempOutStr; 
    }
      

  3.   

    http://www.cnblogs.com/anjou/archive/2007/03/20/681744.html参考一下
      

  4.   

    刚写了点,可能有不足的地方,请自己在修正一下吧。bool GetValueByKey(const TCHAR *pKey,const TCHAR *pScr,TCHAR **ppOutstr ) 

    if (NULL == ppOutstr)
    {
    return false;
    }

    int iKeyLen = _tcslen(pKey); const TCHAR* pStart = NULL;
    pStart = _tcsstr(pScr,pKey);
    if (pStart == NULL)
    {
    return false;
    }
    pStart = pStart + iKeyLen + 2; const TCHAR* pEnd = NULL;
    pEnd = _tcsstr(pStart,pKey);
    if (pEnd == NULL)
    {
    return false;
    }
    pEnd = pEnd - 3; long len = pEnd - pStart + 1; *ppOutstr = new TCHAR[len];
    memset(*ppOutstr, 0, len * sizeof(TCHAR) );
    _tcsncpy(*ppOutstr, pStart,len-1);
    return true;

    //如下是调用
    TCHAR* pScr = _T("scr = <&QQ&>123456</&QQ&>");
    TCHAR* pKey = _T("QQ");
    TCHAR* pOut = NULL;
    bool bGet = GetValueByKey(pKey, pScr, &pOut);
    if (pOut != NULL)
    {
        delete []pOut;
        pOut = NULL;
    }
      

  5.   

    谢谢,但OutValue必须是utf-8的编码啊. 现在得出来的是unicode的编码,还需要一个转换哦.