C 截取字符串

来源:互联网 发布:编程一小时怎么登陆 编辑:程序博客网 时间:2024/05/19 23:14
#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;}} 
原创粉丝点击