枫
枫
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了一个小程序,里面用了stringreplace函数,目的是把一个文本文件里的特定字符替换
成别的字符,但这个程序运行的时候,它只把首先遇到的特定字符替换了以后的特定字符都
没有替换,这是怎么回事呢?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
mystring:tstringlist;
mypath:string;
myflags:TReplaceFlags;
begin
if opendialog1.Execute then
begin
mystring:=tstringlist.Create
mypath:=opendialog1.FileName;
mystring.LoadFromFile(mypath);
memo1.text:=stringreplace(mystring.text,chr(13),'[enter]',myflags);
mystring.Free
end;
end;
end.
成别的字符,但这个程序运行的时候,它只把首先遇到的特定字符替换了以后的特定字符都
没有替换,这是怎么回事呢?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
mystring:tstringlist;
mypath:string;
myflags:TReplaceFlags;
begin
if opendialog1.Execute then
begin
mystring:=tstringlist.Create
mypath:=opendialog1.FileName;
mystring.LoadFromFile(mypath);
memo1.text:=stringreplace(mystring.text,chr(13),'[enter]',myflags);
mystring.Free
end;
end;
end.