function split(src,dec : string):TStringList; var i : integer; str : string; begin result := TStringList.Create; repeat i := pos(dec,src); str := copy(src,1,i-1); if (str='') and (i>0) then begin delete(src,1,length(dec)); continue; end; if i>0then begin result.Add(str); delete(src,1,i+length(dec)-1); end; until i<=0; if src<>''then result.Add(src); end; procedure TForm1.Button1Click(Sender: TObject); var ss : TStringList; str,dec : string; begin str :='1111||2222||||3333|||4444||'; dec :='||'; ss := split(str,dec); memo1.Lines.AddStrings(ss); ss.Free; end;
|
请发表评论