MyChat Scripts: function TStringList.Exchange, swap two strings in a list
"For developers", "Server scripts", "Functions description", "Strings", "TStringList", "Methods", "Exchange".
Swap two strings in the list. From 0 to TStringList.Count - 1
Syntax
procedure TStringList.Exchange(x, y: integer);
Parameters and return values
Parameter |
Type |
Value |
x |
integer |
first string number; |
y |
integer |
first string number. |
Example
var
SL: TStringList;
i: integer;
begin
SL := TStringList.Create;
for i := 1 to 10 do SL.Append(IntToStr(i));
mLogScript(SL.CommaText, 'Before');
for i := 0 to 4 do SL.Exchange(i, 9 - i);
mLogScript(SL.CommaText, 'After');
SL.Free;
end..
Script work result
[17:54:08] (Log "ExchangeMethod"): [Before] 1,2,3,4,5,6,7,8,9,10
[17:54:08] (Log "ExchangeMethod"): [After] 10,9,8,7,6,5,4,3,2,1
[17:54:08] (Run "ExchangeMethod"): Script operation time: 5 ms
[17:54:08] (Run "ExchangeMethod"): Script done successfully.