
01.11.2010, 12:01
|
 |
Прохожий
|
|
Регистрация: 01.11.2010
Сообщения: 4
Репутация: 10
|
|
Считывание и запись в файл
Прошу помочь с одной програмкой. Мне надо было написать програмку которая бы считывала текст из одного файла (*.txt) и записывала этот текст в другой но в другом должен стоять на лимит(не более 60 символов в строке) и остальное содержимое должно переноситься на следующую строку не разрывая слов. У меня есть основа этой программы, но она не входящий в пределы текст просто удаляет. Прошу помочь, вот код
Код:
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
{ Private declarations }
public
{ Public declarations }
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.
|