16,748
社区成员
发帖
与我相关
我的任务
分享
procedure SplitStringList(const source, ch: string; pList: TStrings);
var
pTmp: pchar;
pCh: PChar;
p: PChar;
i,j: integer;
s: string;
iChLen: Integer;
begin
if (Length(Source)= 0) or not Assigned(pList) then
exit;
i:= 0;
iChLen:= Length(ch);
pTmp := pchar(source+ ch);
pCh:= PChar(ch);
p:= StrPos(pTmp,pCh);
if p<> nil then
begin
Inc(p,iChLen);
i:= p- pTmp;
end;
pList.BeginUpdate;
while i> 0 do
begin
j:= i- iChLen;
SetLength(s,i- iChLen);
if j> 0 then
begin
s:= StrLCopy(PChar(s),pTmp,i- iChLen);
plist.Add(s);
end;
pTmp:= p;
p:= StrPos(pTmp,pCh);
if p<> nil then
begin
Inc(p,iChLen);
i:= p- pTmp;
end
else if pTmp<> nil then //保证最后一段字符也能被查找到
i:= StrLen(pTmp)+ iChLen
else
i:=0;
end;
pList.EndUpdate;
end;
var
list:TStringList;
begin
list.Delimiter := ':';
list.DelimitedText := 'a:b:c:';
ShowMessage(list.Text);
end;