您的位置:首页 > 编程语言 > Delphi

delphi的分离字符串函数split-Delphi编程

2008-06-18 17:28 323 查看
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type userarray=array of string;

type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
function split(s: string; dot: char): userarray;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses StrUtils;

{$R *.dfm}

function TForm1.split(s:string;dot:char):userarray;
var
str:userarray;
i,j:integer;
begin
i:=1;
j:=0;
SetLength(str, 255);

while Pos(dot, s) > 0 do
begin
str[j]:=copy(s,i,pos(dot,s)-i);
i:=pos(dot,s) 1;
s[i-1] := chr(ord(dot) 1);
j:=j 1;
end;
str[j]:=copy(s,i,strlen(pchar(s))-i 1);
result:=str;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
ur:userarray;
i:Integer;
begin
ur:=split(Edit1.Text,';');
for i :=0 to 255 do
begin
if length(ur[i])=0 then Exit;
ShowMessage(ur[i]);
end;

end;

end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: