memo1文本内容:
fygjh5jghg
trhfg5jkhh
fjhfhyhdf
6695thu
fjjy5hghfunit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleServer, VBScript_RegExp_55_TLB;type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
Memo3: TMemo;
Button1: TButton;
Button2: TButton;
RegExp1: TRegExp;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
machs: IMatchCollection;
Matchs: Match;
submatch: ISubMatches;
i : integer;
begin
RegExp1.Global := true;
RegExp1.IgnoreCase := True;
RegExp1.Pattern := '5.*';
machs := RegExp1.Execute(memo1.text) as IMatchCollection;
for i := 0 to machs.Count - 1 do
begin
Matchs := machs.Item[i] as Match;
submatch := Matchs.SubMatches as ISubMatches;
memo2.lines.Add(matchs.Value);
end; RegExp1.Pattern := '5';
memo3.Text := RegExp1.Replace(memo2.Text,'');
end;
procedure TForm1.Button2Click(Sender: TObject);
var
machs: IMatchCollection;
Matchs: Match;
submatch: ISubMatches;
i : integer;
aaa : Tstrings;
bbb: Tstrings;
begin
aaa := TStringList.Create;
bbb := TStringList.Create;
RegExp1.Global := true;
RegExp1.IgnoreCase := True;
RegExp1.Pattern := '5.*';
machs := RegExp1.Execute(memo1.text) as IMatchCollection;
for i := 0 to machs.Count - 1 do
begin
Matchs := machs.Item[i] as Match;
submatch := Matchs.SubMatches as ISubMatches;
aaa.Add(matchs.Value);
end; RegExp1.Pattern := '5';
bbb.Text := RegExp1.Replace(aaa.Text,'');
memo3.Text := bbb.Text;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
memo2.Clear;
memo3.Clear;
end;end.为什么按钮1点击后获得的结果是:
jghg
jkhh
thu
hghf而按钮2点击后获得的结果是:
jghgjkhhthuhghf我想使用TStringList不使用memo获得没有空行的结果,请教如何修改代码?
fygjh5jghg
trhfg5jkhh
fjhfhyhdf
6695thu
fjjy5hghfunit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleServer, VBScript_RegExp_55_TLB;type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
Memo3: TMemo;
Button1: TButton;
Button2: TButton;
RegExp1: TRegExp;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
machs: IMatchCollection;
Matchs: Match;
submatch: ISubMatches;
i : integer;
begin
RegExp1.Global := true;
RegExp1.IgnoreCase := True;
RegExp1.Pattern := '5.*';
machs := RegExp1.Execute(memo1.text) as IMatchCollection;
for i := 0 to machs.Count - 1 do
begin
Matchs := machs.Item[i] as Match;
submatch := Matchs.SubMatches as ISubMatches;
memo2.lines.Add(matchs.Value);
end; RegExp1.Pattern := '5';
memo3.Text := RegExp1.Replace(memo2.Text,'');
end;
procedure TForm1.Button2Click(Sender: TObject);
var
machs: IMatchCollection;
Matchs: Match;
submatch: ISubMatches;
i : integer;
aaa : Tstrings;
bbb: Tstrings;
begin
aaa := TStringList.Create;
bbb := TStringList.Create;
RegExp1.Global := true;
RegExp1.IgnoreCase := True;
RegExp1.Pattern := '5.*';
machs := RegExp1.Execute(memo1.text) as IMatchCollection;
for i := 0 to machs.Count - 1 do
begin
Matchs := machs.Item[i] as Match;
submatch := Matchs.SubMatches as ISubMatches;
aaa.Add(matchs.Value);
end; RegExp1.Pattern := '5';
bbb.Text := RegExp1.Replace(aaa.Text,'');
memo3.Text := bbb.Text;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
memo2.Clear;
memo3.Clear;
end;end.为什么按钮1点击后获得的结果是:
jghg
jkhh
thu
hghf而按钮2点击后获得的结果是:
jghgjkhhthuhghf我想使用TStringList不使用memo获得没有空行的结果,请教如何修改代码?
解决方案 »
- 请问:时间延迟--多线程或时间控件中如何解决
- 转换SQL数据库到ACCESS的问题,在线·
- ADOQUERY的datasource属性怎么用
- Delphi写的动态连接库返回值为PChar类型,在VB中如何调用(急,在线等待)
- 菜鸟请大虾指点迷津:我学delphi要多久才能入门?
- 为何我的Active Form发布后在本机(服务器)上可见,在其他人的浏览器内不可见?
- delphi有没有象vc的boundcheck这样的能够检查内存泄漏的工具?
- 十万火急,通过DBGRID对ClientDataSet进行数据更新时的问题!!!!!
- 急急!求救,在Delphi5中如何自动进入Excel,且打开指定的Excel文件名。
- 关于Delphi中的Chart控件
- delphi2010 安装问题
- DELPHI修改IE中的脚本
bbb.Text->bbb.Items.text