---------------------------------
UPDATE 29.01.2022
With Arma 3 2.06+ it is now possible to use regexReplace instead: https://community.bistudio.com/wiki/regexReplace
Performance:
["12345 123456", "123", "abc"] call TER_fnc_editString;
Execution Time: 0.0093 ms | Cycles: 10000/10000 | Total Time: 93 ms
"12345 123456" regexReplace ["123/g", "abc"]
Execution Time: 0.0016 ms | Cycles: 10000/10000 | Total Time: 16 ms
---------------------------------
Hello everyone,
I just wanted to share a small function. It can replace certain parts of a string with your own string.
/*
Author: Terra
Description:
Substitute a certain part of a string with another string.
Parameters:
1: STRING - Source string
2: STRING - Part to edit
3: STRING - Substitution
Returns: STRING
Example:
["12345 123456", "123", "abc"] call TER_fnc_editString;
Returns: "abc45 abc456"
*/
TER_fnc_editString =
{
params ["_str", "_toFind", "_subsitution"];
_char = count _toFind;
_no = _str find _toFind;
while {-1 != _str find _toFind} do {
_no = _str find _toFind;
_splitStr = _str splitString "";
_splitStr deleteRange [(_no +1), _char -1];
_splitStr set [_no, _subsitution];
_str = _splitStr joinString "";
};
_str
};
Additional information: