
代码
1 unit Unit1;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 StdCtrls;
8
9 type
10 TForm1 = class(TForm)
11 Button1: TButton;
12 procedure Button1Click(Sender: TObject);
13 private
14 { Private declarations }
15 public
16 { Public declarations }
17 end;
18
19 var
20 Form1: TForm1;
21
22 implementation
23
24 {$R *.DFM}
25
26 procedure TForm1.Button1Click(Sender: TObject);
27 var
28 s:string;
29 i:integer;
30 begin
31 i:=1;
32 s:='123abc';
33 while(i<=length(s))and(s[i]<>'')do
34 begin
35 s[i]:='f';
36 inc(i);
37 showmessage(inttostr(i));
38 showmessage(s);
39 end;
40 end;
41 end.
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 StdCtrls;
8
9 type
10 TForm1 = class(TForm)
11 Button1: TButton;
12 procedure Button1Click(Sender: TObject);
13 private
14 { Private declarations }
15 public
16 { Public declarations }
17 end;
18
19 var
20 Form1: TForm1;
21
22 implementation
23
24 {$R *.DFM}
25
26 procedure TForm1.Button1Click(Sender: TObject);
27 var
28 s:string;
29 i:integer;
30 begin
31 i:=1;
32 s:='123abc';
33 while(i<=length(s))and(s[i]<>'')do
34 begin
35 s[i]:='f';
36 inc(i);
37 showmessage(inttostr(i));
38 showmessage(s);
39 end;
40 end;
41 end.
本文提供了一个使用Delphi进行字符串替换操作的简单示例。通过一个按钮点击事件,演示了如何遍历并修改字符串中的特定字符。此代码适用于希望了解Delphi中字符串操作基本方法的初学者。
2996

被折叠的 条评论
为什么被折叠?



