索性写段代码贴上来吧:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure Split(const s:string;SepChar:char;var TTL:TstringList);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Split(const s:string;SepChar:char;var TTL:TstringList);
var
Temp:string;
begin
temp:=s;
if temp[1]<>SepChar then temp:=temp+SepChar;
if temp[length(temp)]<>SepChar then temp:=temp+SepChar;
TTL.Clear;
TTL.Delimiter:=SepChar;
TTL.DelimitedText:=temp;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
TL:TstringList;
i:integer;
begin
TL:=TstringList.Create;
Split(edit1.Text,'$',TL);
listbox1.Items.Add(IntToStr(TL.Count));
for i:=0 to TL.Count-1 do
listbox1.Items.Add(tl.Strings);
FreeAndNil(TL);
end;
end.