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, str4, str5 :shortstring;

begin
  str2:='';str3:='';str4:='';str5:='';
  for i:=1 to k do
                 begin
                 str2:=str2+str[i];
                 end;

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

  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 to k do
        begin
        str4:=str4+str2[i];
        str2[i]:=' ';
        end;

str5:=str4+str3;


  edit.text:=str2;
  edit2.text:=str5;
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.
