CStrring splite分割

来源:互联网 发布:常用的hash算法有哪些 编辑:程序博客网 时间:2024/05/20 21:23

bool _splite(CString strSrc, CString strSplite,CStringArray& arDes)
{
 arDes.RemoveAll();//初始化
 while(strSrc.GetLength()>0){
  int   pos   =   strSrc.Find(strSplite,0);//定位分割符
  CString   strLeft;
  if(pos!=-1){
   //定位成功
   strLeft   =   strSrc.Left(pos);//前面的字符串为新的分割单元
   arDes.Add(strLeft);
   strSrc   =   strSrc.Right(strSrc.GetLength()-pos-strSplite.GetLength());//指定新的分割对象  
   if(strSrc.IsEmpty()){
    //如果已空
    arDes.Add(strSrc);//剩下的字符串为分割单元
    break;
   }
  }else{
   //定位不成功
   strLeft   =   strSrc;//将原字符串作为分割单元入目标数组
   arDes.Add(strLeft);
   strSrc.Empty();//清空原字符串
  }
 }
 return   arDes.GetSize()>1;//如果分割单元数量大于1定义为操作成功  
}

原创粉丝点击