{"name":"find","title":"find","type":"command","url":"https://community.bistudio.com/wiki/find","revid":376413,"updated":"2025-10-11T01:04:47Z","groups":["Strings","Arrays"],"status":"ok","games":{"ofpe":"1.00","ofp":"1.99","arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"ofpe 1.00","arma3_since":"0.50","description":"Searches for an array element within an array or an ANSI string within an ANSI string.\n\n> [!NOTE]\n> **Arma 3:** If Unicode support is desired, see forceUnicode.\n\n> [!IMPORTANT]\n> Search is cASe-seNsItiVE!","syntaxes":[{"syntax":"array find element","params":[{"name":"array","type":"Array","description":"array to search in","type_expr":"Array"},{"name":"element","type":"Anything","description":"array element to find","type_expr":"Anything"}],"returns":{"type":"Number","type_expr":"Number","description":"zero-based position of the first array element that matches x, -1 if not found"},"form":"binary","left":{"text":"array"},"right":{"text":"element"}},{"syntax":"string find substring","since":"arma3 1.28","params":[{"name":"string","type":"String","description":"string to search in","type_expr":"String"},{"name":"substring","type":"String","description":"substring to find","type_expr":"String"}],"returns":{"type":"Number","type_expr":"Number","description":"zero-based position of the first sequence of characters that matches substring, -1 if not found"},"form":"binary","left":{"text":"string"},"right":{"text":"substring"}},{"syntax":"string find [substring, indexStart]","since":"arma3 2.02","params":[{"name":"string","type":"String","description":"string to search in","type_expr":"String"},{"name":"substring","type":"String","description":"substring to find","type_expr":"String"},{"name":"indexStart","type":"Number","description":"zero-based index which defines where find starts from","type_expr":"Number"}],"returns":{"type":"Number","type_expr":"Number","description":"zero-based position of the first sequence of characters that matches substring, -1 if not found"},"form":"binary","left":{"text":"string"},"right":{"text":"[substring, indexStart]"}}],"examples":[{"code":["[\"Apples\", \"Oranges\", \"Pears\"] find \"Oranges\"; // returns 1"]},{"code":["[1, [2], [[3]]] find [[3]]; // returns 2 - does not work in OFP, returns -1"]},{"code":["if (magazines player find \"Strela\" != -1) then { hint \"You've got Strela!\"; };"]},{"code":["hint str (\"japa is the man!\" find \"the man!\"); // returns 8"]},{"code":["\"abc\" find \"\"; // returns 0"]},{"code":["\"abcdefghijklmnopqrstuvxyz\" find \"z\"; // returns 24\n\"abcdefghijklmnopqrstuvxyz\" find [\"z\", 20]; // returns 24, better performance"]},{"code":["\"abcßdef\" find \"c\"; // 2\n\"abcßdef\" find \"ß\"; // 3\n\"abcßdef\" find \"d\"; // 5 - before forceUnicode\n\nforceUnicode 0; // since Arma 3 v2.02\n\"abcßdef\" find \"d\"; // 4"]}],"see_also":["in","findIf","forceUnicode"],"notes":[{"user":"Heeeere's Johnny!","date":"2015-01-04T09:38:00Z","text":"Using **nil** on either side of **find** will make the whole statement return Nothing:\n\n```sqf\n_array = [1, 2, nil, 4, 5];\n_result = _array find nil;\nhintSilent str (isNil \"_result\"); // true\n\n_result = nil find 1;\nhintSilent str (isNil \"_result\"); // true\n```"},{"user":"R3vo","date":"2020-07-16T07:33:00Z","text":"If you want to return all occurences of a given string in a string use the following code. Thanks to *sharp.* for providing the code.\n\n```sqf\nprivate _fnc_findStringsInString =\n{\n    params [\"_string\", \"_search\"];\n    if (_string == \"\") exitWith { [] };\n    private _searchLength = count _search;\n    private _return = [];\n    private _i = 0;\n    private _index = 0;\n    while { _index = _string find _search; _index != -1 } do\n    {\n        _string = _string select [_index + _searchLength];\n        _i = _i + _index + _searchLength;\n        _return pushBack _i - _searchLength;\n    };\n    _return;\n};\n[\"Test,123,123,Test\", \"Test\"] call _fnc_findStringsInString; // returns [0, 13]\n```"}]}