BrainDrain Posted December 17, 2006 Posted December 17, 2006 Put an Editbox and a button on the form, leave them named Edit1 and Button 1 respectively.In Button1.OnClick put the following:varmsg:string;begin msg:=Edit1.text; StringReplace(msg, 'hai', 'hello', [rfReplaceAll]); showmessage(msg);end;Type "hai is the same as hai"into the editbox and click the button. Why does the resulting message read"hai is the same as hai"when it should read"hello is the same as hello"as the StringReplace should have replaced all "hai" with "hello"?
FAT64 Posted December 17, 2006 Posted December 17, 2006 (edited) Strictly speaking, StringReplace is a Function and should be called via a variable ...procedure TForm1.Button1Click(Sender: TObject);var msg:string;begin msg:=Edit1.text; msg := StringReplace(msg, 'hai', 'hello', [rfReplaceAll]); showmessage(msg);end;... the above example works perfectly. Edited December 17, 2006 by FAT64
BrainDrain Posted December 17, 2006 Author Posted December 17, 2006 Aah, I racked my brain over that all of yesterday afternoon... Thanks!
FAT64 Posted December 18, 2006 Posted December 18, 2006 (edited) Better still, combine some of the lines ...procedure TForm1.Button1Click(Sender: TObject);var msg:string;begin msg := StringReplace(Edit1.Text, 'hai', 'hello', [rfReplaceAll]); showmessage(msg);end; Edited December 18, 2006 by FAT64
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now