Advertisement
Janilabo

plc

Dec 10th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.73 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.   i, l, x, y, z: Integer;
  43.  
  44. const
  45.   TEXT1 = 'Testing this StrPlace() function';
  46.   TEXT2 = '                                  ';
  47.   BACKWARDS = False;
  48.   ITERATIONS = 3;
  49.   DELAY = 25;
  50.  
  51. begin
  52.   l := Length(TEXT2);  
  53.   x := -(l - 1);
  54.   y := (l + 1);  
  55.   case BACKWARDS of
  56.     True:
  57.     for z := 1 to ITERATIONS do
  58.       for i := y downto x do
  59.       begin
  60.         ClearDebug;
  61.         str := TEXT2;  
  62.         StrPlace(TEXT1, str, i);
  63.         WriteLn('"' + str + '" [' + IntToStr(i) + ']');
  64.         Wait(DELAY);
  65.       end;  
  66.     False:
  67.     for z := 1 to ITERATIONS do
  68.       for i := x to y do
  69.       begin
  70.         ClearDebug;
  71.         str := TEXT2;  
  72.         StrPlace(TEXT1, str, i);
  73.         WriteLn('"' + str + '" [' + IntToStr(i) + ']');
  74.         Wait(DELAY);
  75.       end;    
  76.   end;  
  77. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement