delphi如何分割一个TStringList成多个TStringList
如何按照指定字符分割一个TStringList成多个TStringList例如:sStrList:=TStringList.Create;sStrList.Add('a'...
如何按照指定字符分割一个TStringList成多个TStringList
例如:
sStrList := TStringList.Create;
sStrList.Add('a');
sStrList.Add('b');
sStrList.Add('*');
sStrList.Add('c');
按照*进行分割, 分割成两个TStringList。 展开
例如:
sStrList := TStringList.Create;
sStrList.Add('a');
sStrList.Add('b');
sStrList.Add('*');
sStrList.Add('c');
按照*进行分割, 分割成两个TStringList。 展开
2013-11-07
展开全部
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
SrsList,DestList1,DestList2: TStringList;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
SrsList:=TStringList.Create;
SrsList.Add('a');
SrsList.Add('b');
SrsList.Add('*');
SrsList.Add('c');
SrsList.Add('d');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
SrsList.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i, j: Integer;
begin
DestList1:=Tstringlist.Create;
DestList2:=TStringlist.Create;
try
i:=SrsList.IndexOf('*');
for j:=0 to i-1 do
DestList1.Add(SrsList.Strings[j]);
for j:=i+1 to SrsList.Count-1 do
DestList2.Add(SrsList.Strings[j]);
Memo1.Lines.AddStrings(DestList1);
Memo2.Lines.AddStrings(DestList2);
finally
DestList1.Free;
DestList2.Free;
end;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
SrsList,DestList1,DestList2: TStringList;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
SrsList:=TStringList.Create;
SrsList.Add('a');
SrsList.Add('b');
SrsList.Add('*');
SrsList.Add('c');
SrsList.Add('d');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
SrsList.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i, j: Integer;
begin
DestList1:=Tstringlist.Create;
DestList2:=TStringlist.Create;
try
i:=SrsList.IndexOf('*');
for j:=0 to i-1 do
DestList1.Add(SrsList.Strings[j]);
for j:=i+1 to SrsList.Count-1 do
DestList2.Add(SrsList.Strings[j]);
Memo1.Lines.AddStrings(DestList1);
Memo2.Lines.AddStrings(DestList2);
finally
DestList1.Free;
DestList2.Free;
end;
end;
end.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询