end;
end.
Faylni qayta ishlashni tashkil qilish uchun While takrorlash buyrug’idan foydalanilgan. Bunda EOF funksiyasining qiymati har bir o’qishdan oldin tekshiriladi.
Saqlash tugmasi Memo maydonidagi ma’lumotlarni faylga saqlash imkonini beradi. Navbatdagi satrni Memo maydoniga qo’shish Lines xususiyatining Add uslubi yordamida amalga oshiriladi.
Topshiriqni bajarish namunasi.
Topshiriq: Matnli f fayldagi xar bir so`z boshqasidan bitta «bo`sh joy» bеlgisi bilan ajratilgan bo`lsin. Unda eng ko`p uchraydigan bеlgilarni «*» bеlgisi bilan almashtirib, g faylga yozing.
2. Dasturi.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var f,g:textfile;
s,st:string;
a:string;
b:array[1..255] of integer;
i,j,n:integer;
ch:char;
begin
assignfile(f,edit1.Text);
reset(f);
st:='';
a:='';
while not eof(F) DO
BEGIN
readln(f,s);
st:=st+' '+trim(s);
end;
closefile(f);
n:=0;
for i:=1 to length(st) do if st[i]=' ' then delete(st,i,1);
for i:=1 to length(st) do
begin
if length(st)<1 then continue;
n:=n+1;
a:=a+st[1];
b[n]:=1;
delete(st,1,1);
for j:=1 to length(st) do
if st[j]=a[n] then
begin
if length(st)<1 then continue;
b[n]:=b[n]+1;
delete(st,j,1);
end;
end;
j:=1;
for i:=1 to n do
if b[i]>b[j] then j:=i;
assignfile(g,'yangi.txt');
reset(f);
rewrite(g);
while not eof(F) DO
BEGIN
readln(f,s);
for i:=1 to length(s) do if s[i]=a[j] then s[i]:='*';
writeln(g,s);
end;
closefile(f);
closefile(g);
memo1.Lines.LoadFromFile('yangi.txt');
end;
end.
1>1>
Dostları ilə paylaş: |