tempstr:='A*1*2*7*9*11';
i:=0;
while pos('*',tempstr)>0 do
begin
list[i]:=copy(tempstr,1,pos('*',tempstr)-1);
tempstr:=copy(tempstr,pos('*',tempstr)+1,length(tempstr));
inc(i);
end;
i:=0;
while pos('*',tempstr)>0 do
begin
list[i]:=copy(tempstr,1,pos('*',tempstr)-1);
tempstr:=copy(tempstr,pos('*',tempstr)+1,length(tempstr));
inc(i);
end;
var
I, L: Integer;
Left: AnsiString;
begin
Assert(List <> nil);
List.Clear;
L := Length(Sep);
I := Pos(Sep, S);
while (I > 0) do
begin
Left := StrLeft(S, I - 1);
List.Add(Left);
Delete(S, 1, I + L - 1);
I := Pos(Sep, S);
end;
if S <> '' then
List.Add(S);
end;
同意 chechy(chechy) !!StrToStrings(S: AnsiString; Sep: AnsiString; const List: TStrings);
调用就行了的。
var
a: TStrings;begin
a := TStringList.Create;
StrToString('A*1*2*7*9*11', '*', a);
然后a里面就是A, 1, 2, 7, 9, 11另补:
function StrLeft(const S: AnsiString; Count: Integer): AnsiString;
begin
Result := Copy(S, 1, Count);
end;