delphi根据字符分割字串成数组  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi根据字符分割字串成数组


发现经常需要这个函数,每次都要翻找以前的工程文件,遂发上来方便以后索引。

function Split(const Source,Delimiter:String):SArray;  
var  
  iCount,iPos,iLength: Integer;  
  sTemp: String;  
  aSplit:SArray;  
begin  
  sTemp := Source;  
  iCount := 0;  
  iLength := Length(Delimiter) - 1;  
  repeat  
    iPos := Pos(Delimiter, sTemp);  
    if iPos = 0 then Break  
    else  
    begin  
      Inc(iCount);  
      SetLength(aSplit, iCount);  
      aSplit[iCount - 1] := Copy(sTemp, 1, iPos - 1);  
      Delete(sTemp, 1, iPos + iLength);  
    end;  
  until False;  
  if Length(sTemp) > 0 then  
  begin  
    Inc(iCount);  
    SetLength(aSplit, iCount);  
    aSplit[iCount - 1] := sTemp;  
  end;  
  Result := aSplit;  
end;  
type
  SArray = array of string;
分割类似
str:= 'hello|world';   
arrList := Split(str,'|');
然后 arrList[0] = hello arrList[1] = world

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.076990127563477 seconds