#include
#include
//+------------str is the String that will be split---------------+//
//+------------bystr is the string by which to split str----------+//
//+------------str_array is the array to save splited str---------+//
void split(const CString str,const CString bystr,CStringArray *str_array)
{
int nLen = bystr.GetLength();
int preLoc = 0;
int nowLoc = 0;
while(true)
{
nowLoc = str.Find(bystr,preLoc);
if(nowLoc == -1&&preLoc == 0)
{
CString substr3=str;
str_array->Add(substr3);
break;
}
if(nowLoc == -1&&preLoc != 0)
{
CString substr2=str.Mid(preLoc);
str_array->Add(substr2);
break;
}
CString substr = str.Mid(preLoc,nowLoc-preLoc);
str_array->Add(substr);
preLoc=nowLoc + nLen;
}
}
C 截取字符串
最新推荐文章于 2024-11-11 20:59:33 发布