var strHead,strTail:string; strAll,strAll2:string; for i:=0 to ListBox1.Items.Count-1 do begin strAll:=ListBox1.Items[i]; if Pos('yesterday',strAll)>0 then begin strHead:=Copy(strAll,0,pos('yesterday',strAll)-1); strTail:=Copy(strAll,pos('yesterday',strAll)+9,length(strAll)); strAll2:=strHead+'tommrow'+strTail; ListBox1.Items[i]:=strAll2; end; end;
procedure TForm1.Button1Click(Sender: TObject); var strStrings:TStringList ; begin strStrings:=TStringList.Create; try strStrings.AddStrings (listbox1.Items); strStrings.Text:=StringReplace(strStrings.Text,'yesterday','tommrow',[rfReplaceAll, rfIgnoreCase]); listbox1.Items.Clear; listbox1.Items.AddStrings(strStrings); finally strStrings.Free; end; end;//不知道会不会比楼上快
strHead,strTail:string;
strAll,strAll2:string;
for i:=0 to ListBox1.Items.Count-1 do
begin
strAll:=ListBox1.Items[i];
if Pos('yesterday',strAll)>0 then
begin
strHead:=Copy(strAll,0,pos('yesterday',strAll)-1);
strTail:=Copy(strAll,pos('yesterday',strAll)+9,length(strAll));
strAll2:=strHead+'tommrow'+strTail;
ListBox1.Items[i]:=strAll2;
end;
end;
var
strStrings:TStringList ;
begin
strStrings:=TStringList.Create;
try
strStrings.AddStrings (listbox1.Items);
strStrings.Text:=StringReplace(strStrings.Text,'yesterday','tommrow',[rfReplaceAll, rfIgnoreCase]);
listbox1.Items.Clear;
listbox1.Items.AddStrings(strStrings);
finally
strStrings.Free;
end;
end;//不知道会不会比楼上快
ListBox1.Items.Text :=
StringReplace(ListBox1.Items.Text,'yesterday','tommrow',[rfReplaceAll, rfIgnoreCase]);
不知道有StringReplace函数,那就简单多了。