Advertisement
Janilabo

sp2

Dec 10th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.05 KB | None | 0 0
  1. procedure StrPlace(s: string; var str: string; position: Integer);
  2. var
  3.   d, i, p, c, l, z: Integer;
  4. begin
  5.   z := Length(s);
  6.   if (z > 0) then
  7.   begin  
  8.     l := Length(str);
  9.     if ((l > 0) and not (position > l)) then
  10.     begin        
  11.       p := position;
  12.       case (p > 0) of
  13.         True:  
  14.         begin
  15.           case ((p + z) > l) of
  16.             True: c := ((l - p) + 1);
  17.             False: c := z;          
  18.           end;  
  19.           for i := 1 to c do
  20.             str[((i + p) - 1)] := s[i];
  21.         end;
  22.         False:
  23.         begin
  24.           d := (1 - p);
  25.           if (d < z) then
  26.           begin            
  27.             c := (z - d);
  28.             p := (p + d);
  29.             if ((p + c) > l) then
  30.               c := ((l - p) + 1);
  31.             for i := 1 to c do
  32.               str[((p + i) - 1)] := s[(i + d)];
  33.           end;
  34.         end;
  35.       end;
  36.     end;
  37.   end;
  38. end;
  39.  
  40. var
  41.   str: string;
  42.  
  43. const
  44.   TEXT1 = 'Testi';
  45.   TEXT2 = 'ng!';
  46.  
  47. begin
  48.   str := TEXT1;
  49.   StrPlace(TEXT2, str, 6);
  50.   WriteLn(str);
  51. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement