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 拷贝dbgrid当前行

Delphi 获取其它软件的tlistbox句柄,怎么取得listbox中的数据

关于公历与农历换算和时间处理的单元 calendar.pas

Delphi xe中windows7新的taskbar功能的使用

Delphi 极速字符串替换函数

Delphi hex 相关单元

Delphi2010中tresourcestream流使用

Delphi idhttp中application/x-www-form-urlencoded字符说明

delph记录输出日志

Delphi 在运行时改变控件的大小

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



打赏

取消

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

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

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

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

评论

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

    暂无评论...