Advertisement
Janilabo

sp

Dec 10th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.73 KB | None | 0 0
  1. procedure StrPut(s: string; var str: string; position: Integer);
  2. var
  3.   l, z, c: Integer;
  4.   t: string;
  5. begin
  6.   z := Length(s);
  7.   if (z > 0) then
  8.   begin
  9.     l := Length(str);
  10.     case (position > 0) of
  11.       True:
  12.       case (position > l) of
  13.         False:
  14.         case (position > 1) of
  15.           True:
  16.           case ((position + z) <= l) of
  17.             False: str := (Copy(str, 1, (position - 1)) + s);  
  18.             True: str := (Copy(str, 1, (position - 1)) + s + Copy(str, (position + z), (l - (position + z) + 1)));
  19.           end;
  20.           False:
  21.           case (z >= l) of
  22.             False: str := (s + Copy(str, (position + z), (l - z)));
  23.             True: str := s;
  24.           end;
  25.         end;                
  26.         True:
  27.         case (position = (l + 1)) of
  28.           False:
  29.           begin
  30.             t := StringOfChar(#32, ((position - l) - 1));
  31.             str := (str + t + s);
  32.           end;
  33.           True: str := (str + s);    
  34.         end;
  35.       end;
  36.       False:  
  37.       begin
  38.         c := ((position + z) - 1);
  39.         case (c < 1) of
  40.           True:
  41.           case (c = 0) of
  42.             True: str := (s + str);
  43.             False: str := (s + StringOfChar(#32, (c * -1)) + str);
  44.           end;
  45.           False:
  46.           case (c <= l) of
  47.             False: str := s;
  48.             True: str := (s + Copy(str, (c + 1), (l - c)));
  49.           end;
  50.         end;
  51.       end;
  52.     end;
  53.   end;
  54. end;
  55.  
  56. var
  57.   str: string;      
  58.   i: Integer;
  59.  
  60. const
  61.   TEXT1 = 'Testi';
  62.   TEXT2 = 'ng!';
  63.  
  64. begin
  65.   for i := -15 to 15 do
  66.   begin
  67.     ClearDebug;
  68.     str := TEXT2;  
  69.     StrPut(TEXT1, str, i);
  70.     WriteLn('"' + str + '" [' + IntToStr(Length(str)) + ']');
  71.     Wait(100);
  72.   end;
  73. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement