你要在哪儿分
set @tmplrmc=@departs
while @tmplrmc<>''
begin
set @k=charindex(';',@tmplrmc)
if @k=0
begin
set @lrmc=@tmplrmc
set @tmplrmc=''
end
else
begin
set @lrmc=substring(@tmplrmc,1,@k-1)
set @tmplrmc=stuff(@tmplrmc,1,@k,'')
end
procedure (string str;var array of string)
var
h,i,j,k:Integer;
begin
k:=length(str);
h:=1;
i:=1;
while (j<k) and (i<k) do
begin
while (str=' ') and (i<k) do
i:=i+1;
if i<k then
begin
j:=i+1;
while (str[j]<>' ') and (j<k) do
j:=j+1;
arr[h]:=copy(str,i,j-1+1);
if j<k then
i:=j+1;
h:=h+1;
end;
end;
end;
///分割一个字符串,其中分割的标志是ch
function SplitString(const source,ch:string):tstrings;
function SplitString(const source,ch:string):tstrings;
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;
var
str : string;
StrList: TStringList;
begin
str:='12 4 45 13 14 15 1';
StrList:=TStringList.create;
while pos(' ',str)<>0 do
begin
StrList.add(copy(str,1,pos(' ',str)<>-1));
str:= trim(copy(str,pos(' ',str),length(str))+' ';
end;
if str<>'' then
StrList.add(str);
StrList.free;
end;
答案很多了,可惜都没用动态数组。
var
str : string;
StrList:array of string;
i:Integer;
begin
str:='12 4 45 13 14 15 1'+' ';
while pos(' ',str)<>0 do
begin
if High(StrList)<Low(StrList) then
begin
i:=0;
SetLength(StrList,1);
end
else
begin
i:=High(StrList)-Low(StrList)+1;
SetLength(StrList,i+1);
end;
StrList:=copy(str,1,pos(' ',str)-1));
str:= trim(copy(str,pos(' ',str),length(str))+' ';
end;
end;