本文整理自网络,侵删。
发现经常需要这个函数,每次都要翻找以前的工程文件,遂发上来方便以后索引。
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 android device information
Delphi winapi: getdesktopwindow - 返回桌面窗口的句柄
更多相关阅读请进入《Delphi》频道 >>