【asp.net core】asp.net C++中分割字符串函数,类似PHP中的explode

更新时间:2019-07-01    来源:php函数    手机版     字体:

【www.bbyears.com--php函数】

 代码如下

/*
 * Author : maben
 * Date   : 2014-08-06
 * @szDelimiter : 分割符
 * @strContent  : 待查找的字符串
 * @arrDest     : 保存分割之后的数组
 */

void Explode(TCHAR szDelimiter, CString strContent, CStringArray& arrDest)
{
 arrDest.RemoveAll();
 int nOffset = 0;
 while (true)
 {
  nOffset = strContent.ReverseFind(szDelimiter);
  if (nOffset == -1)
  {
   if (!strContent.IsEmpty())
    arrDest.Add(strContent);
   break;
  }
  CString strItem = strContent.Mid(nOffset+1);
  if (!strItem.IsEmpty())
  {
   arrDest.Add(strItem);
  }
  strContent = strContent.Left(nOffset);
 }
}

本文来源:http://www.bbyears.com/jiaocheng/56050.html