m2:= Form1.Memo2.Lines.Count-2;
for i:=0 to m2 do
begin
s:=Form1.Memo2.Lines.Strings[i];
tmp:=Form1.Memo2.Lines.Strings[i];
index:=Pos(',',Form1.Memo2.Lines.Strings[i]);
tmp:=copy(Form1.Memo2.Lines.Strings[i],index+1,length(Form1.Memo2.Lines.Strings[i])-index );
Form1.Memo2.Lines.Strings[i]:=copy(Form1.Memo2.Lines.Strings[i],1,index+Pos( ',', tmp )-1 ) ;
end;我就是想把每一条数据中,从第二个逗号开始后面的数据都不要当数据比较少时,几百条执行还可以,当数据达到几千条时,执行的非常慢,请问有什么优化方法或者更好的方法呢???
for i:=0 to m2 do
begin
s:=Form1.Memo2.Lines.Strings[i];
tmp:=Form1.Memo2.Lines.Strings[i];
index:=Pos(',',Form1.Memo2.Lines.Strings[i]);
tmp:=copy(Form1.Memo2.Lines.Strings[i],index+1,length(Form1.Memo2.Lines.Strings[i])-index );
Form1.Memo2.Lines.Strings[i]:=copy(Form1.Memo2.Lines.Strings[i],1,index+Pos( ',', tmp )-1 ) ;
end;我就是想把每一条数据中,从第二个逗号开始后面的数据都不要当数据比较少时,几百条执行还可以,当数据达到几千条时,执行的非常慢,请问有什么优化方法或者更好的方法呢???
index:=Pos(',',Form1.Memo2.Lines.Strings[i]);
if index <> 0 then
begin
index:=Pos(',',Form1.Memo2.Lines.Strings[i], index);
if index <> 0 then
Form1.Memo2.Lines.Strings[i]:=copy(Form1.Memo2.Lines.Strings[i],1, index - 1);
begin
index:=Pos(',',Form1.Memo2.Lines.Strings[i]);
if index <> 0 then
begin
index:=Pos(',',Form1.Memo2.Lines.Strings[i], index);
if index <> 0 then
Form1.Memo2.Lines.Strings[i]:=copy(Form1.Memo2.Lines.Strings[i],1, index - 1);
end;
end;
uses StrUtils;for i:=0 to m2 do
begin
index:=Pos(',',Form1.Memo2.Lines.Strings[i]);
if index <> 0 then
begin
index:=PosEx(',',Form1.Memo2.Lines.Strings[i], index);
if index <> 0 then
Form1.Memo2.Lines.Strings[i]:=copy(Form1.Memo2.Lines.Strings[i],1, index - 1);
end;
end;
建一个 TStringList,把Memo的内容赋给 StringList,然后对 StringList进行处理,完成后再赋给 Memo