Janilabo

Janilabo | StuffEx() [SCAR Divi]

Apr 28th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.20 KB | None | 0 0
  1. {==============================================================================]  
  2.   Explanation: Returns str stuffed with s.
  3.                pos1=start position, pos2=finish position.
  4.                With pos1 > pos2 s will be reversed.                  
  5. [==============================================================================}
  6. function StuffEx(str, s: string; pos1, pos2: Integer): string;
  7. var
  8.   i, l: Integer;
  9. begin
  10.   Result := str;
  11.   l := Length(Result);
  12.   if (pos1 < 1) then
  13.     pos1 := 1;
  14.   if (pos1 > l) then
  15.     pos1 := l;
  16.   if (pos2 < 1) then
  17.     pos2 := 1;
  18.   if (pos2 > l) then
  19.     pos2 := l;
  20.   case (pos1 > pos2) of
  21.     True:
  22.     begin          
  23.       Delete(Result, pos2, ((pos1 - pos2) + 1));
  24.       l := Length(s);
  25.       SetLength(str, l);
  26.       for i := l downto 1 do    
  27.         str[i] := Char(s[((l - i) + 1)]);
  28.       Insert(str, Result, pos2);
  29.     end;
  30.     False:
  31.     begin
  32.       Delete(Result, pos1, ((pos2 - pos1) + 1));
  33.       Insert(s, Result, pos1);
  34.     end;  
  35.   end;
  36. end;
  37.  
  38. var
  39.   str: string;
  40.  
  41. begin
  42.   ClearDebug;
  43.   str := 'StuffEx test to see this is working..!';
  44.   WriteLn(StuffEx(str, '() WORKS', 8, 37));
  45.   WriteLn(StuffEx(str, 'SKROW )(', 37, 8));
  46. end.
Advertisement
Add Comment
Please, Sign In to add comment