Janilabo

Janilabo | TSAPosEx() [SCAR Divi]

Apr 27th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.02 KB | None | 0 0
  1. {==============================================================================]  
  2.   Explanation: Returns all positions of TSA which match with str.                
  3. [==============================================================================}
  4. function TSAPosEx(TSA: TStrArray; str: string): TIntArray;
  5. var
  6.   i, r, h: Integer;
  7. begin
  8.   h := High(TSA);  
  9.   if (h > -1) then
  10.   begin
  11.     SetLength(Result, (h + 1));
  12.     for i := 0 to h do
  13.       if (TSA[i] = str) then
  14.       begin
  15.         Result[r] := i;
  16.         Inc(r);
  17.       end;
  18.   end;
  19.   SetLength(Result, r);
  20. end;
  21.  
  22. begin
  23.   WriteLn(TIAToStr(TSAPosEx(['a', 'b', 'c', 'd', 'c', 'b', 'a'], '_')));
  24.   WriteLn(TIAToStr(TSAPosEx(['a', 'b', 'c', 'd', 'c', 'b', 'a'], 'a')));
  25.   WriteLn(TIAToStr(TSAPosEx(['a', 'b', 'c', 'd', 'c', 'b', 'a'], 'b')));
  26.   WriteLn(TIAToStr(TSAPosEx(['a', 'b', 'c', 'd', 'c', 'b', 'a'], 'c')));
  27.   WriteLn(TIAToStr(TSAPosEx(['a', 'b', 'c', 'd', 'c', 'b', 'a'], 'd')));
  28.   WriteLn(TIAToStr(TSAPosEx(['a', 'b', 'c', 'd', 'c', 'b', 'a'], 'x')));
  29. end.
Advertisement
Add Comment
Please, Sign In to add comment