Прошу помочь с одной програмкой. Мне надо было написать програмку которая бы считывала текст из одного файла (*.txt) и записывала этот текст в другой но в другом должен стоять на лимит(не более 60 символов в строке) и остальное содержимое должно переноситься на следующую строку не разрывая слов. У меня есть основа этой программы, но она не входящий в пределы текст просто удаляет. Прошу помочь, вот код
Код:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
files,files2:TextFile;
str,str2:string;
begin
str2:='';
if not FileExists('test.txt') then exit;
AssignFile(files,'test.txt');
Reset(files);
while not Eof(files) do
begin
ReadLn(files, str);
AssignFile(files2,'test2.txt');
Append(files2);
for i:=1 to length(str) do
begin
if i>60 then break;
if str[i]<>' ' then
str2:=str2+str[i] else
str2:=str2+' ';
end;
Writeln(files2,str2);
closefile(files2);
str2:='';
end;
closefile(files);
end;
end.
|