unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit4: TEdit;
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);

        private
    { Private declarations }
  public
    { Public declarations }
  end;
   procedure split(str:shortstring; k:integer; Edit,edit2:TEdit);
var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
edit3.text:='10';
end;

procedure split(str:shortstring; k:integer; Edit,edit2:TEdit);
Var i,n:integer;
    str2, str3:shortstring;

begin
  str2:='';str3:='';


  if str[k]=' ' then
        n:=k
  else
        begin
        for i:=k downto 1 do
                begin
                if str[i]=' ' then
                        begin
                        n:=i;
                        break;
                        end;
                end;
        end;


  for i:=n+1 to length(str) do
                begin
                str3:=str3+str[i];
                end;


  for i:=1 to n do
        begin
        str2:=str2+str[i];
        end;

    while n < k do
        begin
          str2:=str2+' ';
          inc(n);
        end;


  edit.text:=str2;
  edit2.text:=str3;
end;



procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var str1:shortstring; k:integer;
begin
str1:=edit1.text;
k:=strtoint(edit3.Text);
if key=#13 then split(str1,k,edit2,edit4);
end;



end.
