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

相关阅读 >>

Delphi 数据类型列表

Delphi insert 插入一个字符(串)

Delphi android device information

Delphi winapi: getdesktopwindow - 返回桌面窗口的句柄

Delphi 查找某目录下的特定文件

Delphi写进程管理器

Delphi之autorun(复制自身+循环扫描)

Delphi 提取字符中的数字

Delphi改变文件夹图标

Delphi判断线程是否释放

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...