Janilabo

arghhh

Apr 1st, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.61 KB | None | 0 0
  1. const
  2.   BUGGY_STYLE = False;
  3.  
  4. {==============================================================================]  
  5.   Explanation: Replaces all findStrArr items in TSA with replaceStr. - BUGGY?!                
  6. [==============================================================================}
  7. function TSAReplaceMultiA(TSA, findStrArr: TStrArray; replaceStr: string): TStrArray;
  8. var
  9.   h, h2, i, i2: Integer;
  10. begin
  11.   h := High(findStrArr);
  12.   h2 := High(TSA);
  13.   SetLength(Result, (h2 + 1));
  14.   if ((h >= 0) and (h2 >= 0)) then
  15.     for i := 0 to h do
  16.       for i2 := 0 to h2 do  
  17.         Result[i2] := Replace(TSA[i2], findStrArr[i], replaceStr);
  18. end;
  19.  
  20. {==============================================================================]  
  21.   Explanation: Replaces all findStrArr items in TSA with replaceStr. WORKS...            
  22. [==============================================================================}
  23. function TSAReplaceMultiB(TSA, findStrArr: TStrArray; replaceStr: string): TStrArray;
  24. var
  25.   h, h2, i, i2: Integer;
  26. begin
  27.   h := High(findStrArr);
  28.   h2 := High(TSA);
  29.   Result := TSA;
  30.   if ((h >= 0) and (h2 >= 0)) then
  31.     for i := 0 to h do
  32.       for i2 := 0 to h2 do  
  33.         Result[i2] := Replace(Result[i2], findStrArr[i], replaceStr);
  34. end;
  35.  
  36. var
  37.   h, i: Integer;
  38.   a, b: TStrArray;
  39.  
  40. begin
  41.   a := ['Test1', 'Test2', 'Test3', 'Test4'];
  42.   b := a;
  43.   SetLength(a, 0);
  44.   h := High(b);        
  45.   case BUGGY_STYLE of
  46.     True: b := TSAReplaceMultiA(b, ['Test'], 'Item');
  47.     False: b := TSAReplaceMultiB(b, ['Test'], 'Item');
  48.   end;
  49.   for i := 0 to h do
  50.     WriteLn(b[i]);
  51.   SetLength(b, 0);
  52. end.
Advertisement
Add Comment
Please, Sign In to add comment