VC6用Boost库完成替换和取值

void CBoostTestDlg::OnButton1()
{
    // TODO: Add your control notification handler code here
    UpdateData();
    CWnd* pWnd1=GetDlgItem(IDC_EDIT1);
    CString org_str;
    pWnd1->GetWindowText(org_str);    

    CString regStr;
    CWnd* pWnd2=GetDlgItem(IDC_EDIT2);
    pWnd2->GetWindowText(regStr);
    
    regex expression(regStr);

    CString out_str="";
    cmatch what;
    if(regex_match(org_str, what, expression))
    {
        int size=what.size();

        for(int i=1;i<what.size();i++)
        {
            //char ss[1024];
            //::sprintf(ss,"%s",what[i]);
            out_str.Format("%s   match[%d] is \"%s\"",out_str,i,CString(what[i].first, what.length(i)));
           
        }
           
    }
    CWnd* pWnd3=GetDlgItem(IDC_EDIT3);
    pWnd3->SetWindowText(out_str);
    UpdateData(FALSE);
///////////////////////////////////////
//以下是替换操作
/*UpdateData();
    CWnd* pWnd1=GetDlgItem(IDC_EDIT1);
    CString org_str;
    pWnd1->GetWindowText(org_str);   

    CString regStr;
    CWnd* pWnd2=GetDlgItem(IDC_EDIT2);
    pWnd2->GetWindowText(regStr);
   
    CWnd* pWnd3=GetDlgItem(IDC_EDIT3);
    CString repStr;
    pWnd3->GetWindowText(repStr);

    boost::regex e(regStr);

    CString out_str="";
    cmatch what;
    if(regex_match(org_str, what, e))
    {
        std::string tempstr=boost::regex_replace(std::string(org_str),e,std::string(repStr));
        out_str=CString(tempstr.c_str());
    }
   
    pWnd3->SetWindowText(out_str);
    UpdateData(FALSE);*/
}



posted @ 2007-06-26 09:45  吾非无心  阅读(431)  评论(0编辑  收藏  举报