在MFC中分割字符串,主要是利用CString函数

目的是从下列字符串提取出IP和端口号

CString  temp="227 Entering passive mode <172,18,16,176,229,252>";

void CmfcTestDlg::OnBnClickedOk()

{
    // TODO: 在此添加控件通知处理程序代码
    CString  temp="227 Entering passive mode <172,18,16,176,229,252>";

    int base=temp.Find('<');
    int top=temp.Find('>');
    str=temp.Mid(base+1,top-base-1);
    //MessageBox(str);

    base=0;
    top=str.GetLength()-1;
    int index;
    CString store[6];
    int i=0;
    while(true)
    {
        index=str.Find(',');
         //如果找不到,返回值是-1,又在此浪费了许多时间
        if(-1==index)
        {
            break;
        }
        base=0;
        store[i]=str.Mid(base,index-base);
        MessageBox(store[i]);
        i++;

        top=str.GetLength()-1;
        str=str.Right(top-index);
        
    }
    store[i]=str;
    MessageBox(store[i]);

    CDialogEx::OnOK();
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值