Задание:
Код
Разработать процедуру, которая удаляет слова, начинающиеся на заданую букву в заданом стринге.
На основе разработаной процедуры преобразовать текст оодного тхт файла в новый.
На основе разработаной процедуры преобразовать текст оодного тхт файла в новый.
Вот прога:
Program DeleteWord;
Uses CRT;
Var f1,f2: text;
f1name,f2name,st: string;
s,s1: char;
Procedure delword(Var st:string; s:char);
Const delimiter=[' ',',','.','?','!','(',')','/'];
Var i: byte;
begin
If s in [#65..#90] then s1:=Chr(Ord(s)+32) else s1:=Upcase(s);
i:=1;
While i<=length(st) do
If (i=1) and ((st[i]=s)or(st[i]=s1)) then
Repeat delete(st,i,1) Until st[i] in delimiter else
If (st[i] in delimiter) and ((st[i+1]=s)or(st[i+1]=s1)) then
Repeat delete(st,i+1,1) Until st[i+1] in delimiter else
Inc(i)
{If (i=1) and (st[i]=s) then delete(st,i,Pos(' ',st)-i) else
If (st[i]=' ') and (st[i+1]=s) then delete(st,i,Pos(' ',st)-i) else
Inc(i)}
end;
Begin
clrscr;
Repeat
Writeln('Введите имя файла'); readln(f1name);
assign(f1,f1name);
{$I-}
reset(f1);
{$I+}
if IOResult<>0 then
writeln('Неверно!!');
Until IOResult=0;
f2name:='new'+f1name;
assign(f2,f2name); rewrite(f2);
Writeln('Введите букву'); readln(s);
While not EOF(f1) do
begin
readln(f1,st);
delword(st,s);
writeln(f2,st);
end;
Writeln('Текст, без слов с 1-й буквой"',s,'" или "',s1,'") занесен в (',f2name,')');
close(f1);
close(f2);
Readln;
End.
Пример тхт:
Цитата
Welcome to BPL70N15.ZIP, a collection of fast replacement libraries
for your Turbo Pascal 7.0 / Borland Pascal 7.0 compiler. There are
three libraries in this package, a real mode library (TURBO.TPL), a
DOS protected mode library (TPP.TPL), and a Windows library (TPW.TPL).
Every file is a complete, replacement for the original library bearing,
the same name that came with your Pascal compiler. Due to the many
optimizations in the replacement libraries, many programs compiled
with these libraries will run faster. For more detailed information
on possible performance improvements, see the file PERFORM.DOC. Only
performance information for real mode and DOS protected mode programs
can be provided at the moment!
for your Turbo Pascal 7.0 / Borland Pascal 7.0 compiler. There are
three libraries in this package, a real mode library (TURBO.TPL), a
DOS protected mode library (TPP.TPL), and a Windows library (TPW.TPL).
Every file is a complete, replacement for the original library bearing,
the same name that came with your Pascal compiler. Due to the many
optimizations in the replacement libraries, many programs compiled
with these libraries will run faster. For more detailed information
on possible performance improvements, see the file PERFORM.DOC. Only
performance information for real mode and DOS protected mode programs
can be provided at the moment!