BrainDrain Posted December 17, 2006 Share 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"? Link to comment Share on other sites More sharing options...
FAT64 Posted December 17, 2006 Share 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 Link to comment Share on other sites More sharing options...
BrainDrain Posted December 17, 2006 Author Share Posted December 17, 2006 Aah, I racked my brain over that all of yesterday afternoon... Thanks! Link to comment Share on other sites More sharing options...
FAT64 Posted December 18, 2006 Share 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now