type TResultArray = array of string; function Explode(const source, ch: string): TResultArray; var temp: string; i: integer; begin temp := source; i := pos(ch, source); while i <> 0 do begin SetLength(Result, Length(Result) + 1); Result[Length(Result) - 1] := copy(temp, 0, i - 1); delete(temp, 1, i); i := pos(ch, temp); end; SetLength(Result, Length(Result) + 1); Result[Length(Result) - 1] := Temp; end;
循环: procedure TForm1.Button1Click(Sender: TObject); var ss: string; Temp: string; begin ss:='111*111*111'; while Pos('*', ss)<>0 do begin Temp:= copy(ss, 1, Pos('*',ss)-1); ss := copy(ss, pos('*',ss)+1, Length(ss)); showmessage(temp); end; showmessage(ss); end;
//以前别人给的^_^ function StrToStrs(Source,SplStr:String):TStrings; var s:String; i:Integer; ResList:TStrings; begin ResList:=TStringList.Create; s:=Source; i:=Pos(SplStr,S); while i<> 0 do begin ResList.Add(Copy(S,1,i-1)); S:=Copy(S,i+1,Length(S)-i); i:=Pos(SplStr,S); end; ResList.Add(S); Result:=ResList; end;
function StrToStrs(Source,SplStr:String):TStrings; var s:String; i:Integer; ResList:TStrings; begin ResList:=TStringList.Create; s:=Source; i:=Pos(SplStr,S); while i<> 0 do begin ResList.Add(Copy(S,1,i-1)); delete(S,0,i); i:=Pos(SplStr,S); end; if i=0 and s<>'' then ResList.Add(S); Result:=ResList; end;
TResultArray = array of string;
function Explode(const source, ch: string): TResultArray;
var
temp: string;
i: integer;
begin
temp := source;
i := pos(ch, source);
while i <> 0 do
begin
SetLength(Result, Length(Result) + 1);
Result[Length(Result) - 1] := copy(temp, 0, i - 1);
delete(temp, 1, i);
i := pos(ch, temp);
end;
SetLength(Result, Length(Result) + 1);
Result[Length(Result) - 1] := Temp;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ss: string;
Temp: string;
begin
ss:='111*111*111';
while Pos('*', ss)<>0 do
begin
Temp:= copy(ss, 1, Pos('*',ss)-1);
ss := copy(ss, pos('*',ss)+1, Length(ss));
showmessage(temp);
end;
showmessage(ss);
end;
function StrToStrs(Source,SplStr:String):TStrings;
var s:String;
i:Integer;
ResList:TStrings;
begin
ResList:=TStringList.Create;
s:=Source;
i:=Pos(SplStr,S);
while i<> 0 do
begin
ResList.Add(Copy(S,1,i-1));
S:=Copy(S,i+1,Length(S)-i);
i:=Pos(SplStr,S);
end;
ResList.Add(S);
Result:=ResList;
end;
var s:String;
i:Integer;
ResList:TStrings;
begin
ResList:=TStringList.Create;
s:=Source;
i:=Pos(SplStr,S);
while i<> 0 do
begin
ResList.Add(Copy(S,1,i-1));
delete(S,0,i);
i:=Pos(SplStr,S);
end;
if i=0 and s<>'' then ResList.Add(S);
Result:=ResList;
end;