I thought I’d share this function I wrote back in the days when I was helping with DayZ Mod. The original BIS function used by Rocket was grossly unoptimised while also heavily used in the mod. We had few proposals for improvement, mine happened to be the fastest. I think it is still used in DayZ Mod today.

Anyway, instead of copying and pasting the old code, I decided to improve it a bit more and make the use of some of the inbuilt BIS functions like a pro. So here it is:

KK_fnc_inString = { /* Author: Killzone_Kid Description: Find a string within a string (case insensitive) Parameter(s): _this select 0: <string> string to be found _this select 1: <string> string to search in Returns: Boolean (true when string is found) How to use: _found = ["needle", "Needle in Haystack"] call KK_fnc_inString; */ private ["_needle","_haystack","_needleLen","_hay","_found"]; _needle = [_this, 0, "", [""]] call BIS_fnc_param; _haystack = toArray ([_this, 1, "", [""]] call BIS_fnc_param); _needleLen = count toArray _needle; _hay = +_haystack; _hay resize _needleLen; _found = false; for "_i" from _needleLen to count _haystack do { if (toString _hay == _needle) exitWith {_found = true}; _hay set [_needleLen, _haystack select _i]; _hay set [0, "x"]; _hay = _hay - ["x"] }; _found };

By now you are probably wondering, how does this function compare to BIS official function – BIS_fnc_inString, which is supposed to do the same thing? I think I should mention that in ArmA 3 BIS_fnc_inString is not the same as the one in ArmA 2, it has been rewritten and possibly improved.

So I have constructed a devious test where the needle would be at the end of the haystack but also that haystack would have a lot of near matches. After some code performance testing here is the result:


My function is almost 4 times faster than official. As you can see from the function code, the speed of the function depends on the length of the haystack minus length of the needle. Because of that the function performance is predictable and reliable. Since I’m not BIS employee I don’t think there any chance for this function making it to ArmA 3, however if BIS peeps are reading, take it, I don’t want anything for it. No? Then maybe use it as a template to improve the official one?

But I tell you what, all this is a child’s play in comparison to what real men do when they need string search. I have done the same code performance test on RegEx extension I’ve made earlier (gotta start pushing that documentation out grrr).


Oh yeah! That is 76 times faster than my inString function and 290 times faster than the official one, LMAO!