MFC-CSTRING 字符串分割

2230阅读 0评论2015-03-06 vivieu
分类:Windows平台

MFC-CSTRING 字符串分割

CString strSrc = _T("1++2+3+4");
CStringArray strResult;

CString strGap = _T("+"); int nPos = strSrc.Find(strGap);

CString strLeft = _T(""); while(0 <= nPos)
{
    strLeft = strSrc.Left(nPos); if (!strLeft.IsEmpty())
        strResult.Add(strLeft);

    strSrc = strSrc.Right(strSrc.GetLength() - nPos - 1);
    nPos = strSrc.Find(strGap);
} if (!strSrc.IsEmpty()) {
   strResult.Add(strSrc);
} int nSize = strResult.GetSize(); for (int i = 0; i < nSize; i++)
{
    OutputDebugString(strResult.GetAt(i) + _T("\n"));
}

上一篇:86五笔口诀
下一篇:print 和printf 函数使用的转义序列