CString的split功能

mfc的CString沒有split方法,自己實現之:

// 分割
void CdecDemoDlg::SplitStr(CString strSrc, CString strGap, CStringArray &strResult)
{
 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 - strGap.GetLength());
  nPos = strSrc.Find(strGap);
 }

 if (!strSrc.IsEmpty())
 {
  strResult.Add(strSrc);
 }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章