Janilabo

Janilabo | TSAStuff() [SCAR Divi]

Apr 27th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.32 KB | None | 0 0
  1. {==============================================================================]  
  2.   Explanation: Returns TSA stuffed with strs.
  3.                iFrom=start position, iCount=count of chars to stuff with.                  
  4. [==============================================================================}
  5. function TSAStuff(TSA, strs: TStrArray; iFrom, iCount: Integer): TStrArray;
  6. var
  7.   h, i, l: Integer;
  8. begin
  9.   l := Length(TSA);
  10.   SetLength(Result, l);
  11.   for i := 0 to (l - 1) do
  12.     Result[i] := string(TSA[i]);  
  13.   if (iFrom < 0) then
  14.     iFrom := 0;
  15.   if (iFrom > (l - 1)) then
  16.     iFrom := (l - 1);
  17.   if ((iCount > 0) and (iFrom <= (l - 1))) then
  18.     Delete(Result, iFrom, iCount);            
  19.   h := High(strs);
  20.   if (h > -1) then
  21.   begin        
  22.     l := Length(Result);                            
  23.     SetLength(Result, (l + (h + 1)));
  24.     if (iFrom > l) then
  25.       iFrom := l;      
  26.     for i := (l + h) downto (iFrom + (h + 1)) do
  27.       Swap(Result[i], Result[(i - (h + 1))]);  
  28.     for i := 0 to h do
  29.       Result[(i + iFrom)] := string(strs[i]);      
  30.   end;          
  31. end;
  32.  
  33. var
  34.   a, b: TStrArray;
  35.   h, i: Integer;
  36.  
  37. begin
  38.   ClearDebug;
  39.   a := ['a', 'b', 'b', 'x', 'y', 'z', 'f', 'f', 'g'];
  40.   b := TSAStuff(a, ['c', 'd', 'e'], 2, 5);
  41.   h := High(b);
  42.   for i := 0 to h do
  43.     WriteLn(b[i]);
  44. end.
Advertisement
Add Comment
Please, Sign In to add comment