delphitstrings和tstringlist的區(qū)別?
dephi中沒有象vb中的split函數(shù),但是使用tstringlist類的delimter和delimtedtext兩個(gè)屬性可以很容易的把字符串分割,然后放入tstrings里面.
例:
s:='aa,bb,cc,dd'
ts:=tstringlist.create
ts.delimter:=','
ts.delimtedtext:=s
//這時(shí)ts里面就存放了aabbccdd這四個(gè)strings了.你只要通過ts[0]就可以取第一個(gè)數(shù)據(jù)
functionsplitstring(source,deli:string):tstringlist;stdcall;
var
endofcurrentstring:byte;
stringlist:tstringlist;
begin
stringlist:=tstringlist.create;
whilepos(deli,source)>0do
begin
endofcurrentstring:=pos(deli,source);
stringlist.add(copy(source,1,endofcurrentstring-1));
source:=copy(source,endofcurrentstring+length(deli),length(source)-endofcurrentstring);
end;
result:=stringlist;
stringlist.add(source);
end;
procedurestrtostrs(str:string;strs:tstrings);
vartemp:string;
i:integer;
labelb,e;
begin
b:
i:=ansipos('|',str);
ifi=0thengotoe;
strs.add(ansileftstr(str,i-1));
str:=ansirightstr(str,length(str)-i);
gotob;
e:
end;