做一个返回数组的函数(例子)
2006-02-04 13:44:50 来源:WEB开发网核心提示: type TArray = array of string;PRocedure TrimChar(s:string;var sRet : TArray); function CountChar(s:string; c:char):integer; var i : integer; begin result
type
TArray = array of string;
PRocedure TrimChar(s:string;var sRet : TArray);
function CountChar(s:string; c:char):integer;
var
i : integer;
begin
result := 0;
for i := 1 to Length(s) do
if s[i] = c then Inc(result);
end;
var
ipos : integer;
i : integer;
begin
SetLength(sRet, CountChar(s, ',') + 1);
iPos := Pos(',', s);
i := 0;
while iPos > 0 do
begin
sRet[i] := Copy(s, 1, iPos - 1);
Delete(s, 1, iPos);
iPos := Pos(',', s);
Inc(i);
end;
sRet[i] := s;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
sA : TArray;
s : string;
i : integer;
begin
s := 'abc,cd,mm,44';
sA := nil;
TrimChar(s, sA);
for i := Low(sA) to High(sA) do
Memo1.Lines.Add(sA[i]);
end;
更多精彩
赞助商链接