分割字符串

I

import

Unregistered / Unconfirmed
GUEST, unregistred user!
type
TResultArray = array of string;
function SplitString(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;
**************
function SplitString(const source,ch:string):tstringlist;
var
temp:string;
i:integer;
begin
result:=tstringlist.Create;
temp:=source;
i:=pos(ch,source);
while i<>0 do
begin
result.Add(copy(temp,0,i-1));
delete(temp,1,i);
i:=pos(ch,temp);
end;
result.Add(temp);
end;
调用:
s:=splitstring('afsdfsdaaa|bbfdsfsdb|ccc','|');
for i:=0 to s.Count-1 do
b:=b+s.Strings+#13;
showmessage(b);
s.free;
 

Similar threads

S
回复
0
查看
622
SUNSTONE的Delphi笔记
S
S
回复
0
查看
593
SUNSTONE的Delphi笔记
S
I
回复
0
查看
590
import
I
I
回复
0
查看
656
import
I
顶部