unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TResultArray = array of string;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function SplitString(const source, ch: string): Tstringlist ;
// function SplitString(const source, ch: string): TResultArray ;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
s: Tstringlist;
// s : TResultArray;
i :integer;
b : string;
begin
s:=splitstring('afsdfsdaaa|bbfdsfsdb|ccc','|');
for i:=0 to s.Count-1 do
b:=b + s.Strings
+ #13;
// b:=b + s.+ #13;
showmessage(b);
s.free;
end;
function TForm1.SplitString(const source, ch: string): Tstringlist;
var
temp: string;
i: integer;
begin
result := tstringlist.Create;
temp := source;
i := pos(ch, source);
while i <> 0 do
begin
result.Add(copy(temp, 0, i - 1));
delete(temp, 1, i);
i := pos(ch, temp);
end;
result.Add(temp);
end;
{
function TForm1.SplitString(const source, ch: string): TResultArray;
var
temp: string;
i: integer;
begin
temp := source;
i := pos(ch, source);
while i <> 0 do
begin
SetLength(Result, Length(Result) + 1);
Result[Length(Result) - 1] := copy(temp, 0, i - 1);
delete(temp, 1, i);
i := pos(ch, temp);
end;
SetLength(Result, Length(Result) + 1);
Result[Length(Result) - 1] := Temp;
end;
}
end.