{"name":"find","operator":null,"title":"find","type":"command","url":"https://community.bistudio.com/wiki/find","revid":376413,"updated":"2025-10-11T01:04:47Z","groups":["Strings","Arrays"],"status":"ok","replaced_by":[],"games":[{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"ofp","name":"Operation Flashpoint","version":"1.99"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"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","since":null,"effect":null,"exec":null,"params":[{"name":"array","type":"Array","optional":false,"default":null,"description":"array to search in","types":["Array"],"since":null,"text":"array: Array - array to search in"},{"name":"element","type":"Anything","optional":false,"default":null,"description":"array element to find","types":["Anything"],"since":null,"text":"element: Anything - array element to find"}],"returns":{"type":"Number","types":["Number"],"description":"zero-based position of the first array element that matches x, -1 if not found","text":"Number - zero-based position of the first array element that matches x, -1 if not found"},"form":"binary","operator":null,"left":{"text":"array","types":["Array"]},"right":{"text":"element","types":["Anything"]}},{"syntax":"string find substring","since":"arma3 1.28","effect":null,"exec":null,"params":[{"name":"string","type":"String","optional":false,"default":null,"description":"string to search in","types":["String"],"since":null,"text":"string: String - string to search in"},{"name":"substring","type":"String","optional":false,"default":null,"description":"substring to find","types":["String"],"since":null,"text":"substring: String - substring to find"}],"returns":{"type":"Number","types":["Number"],"description":"zero-based position of the first sequence of characters that matches substring, -1 if not found","text":"Number - zero-based position of the first sequence of characters that matches substring, -1 if not found"},"form":"binary","operator":null,"left":{"text":"string","types":["String"]},"right":{"text":"substring","types":["String"]}},{"syntax":"string find [substring, indexStart]","since":"arma3 2.02","effect":null,"exec":null,"params":[{"name":"string","type":"String","optional":false,"default":null,"description":"string to search in","types":["String"],"since":null,"text":"string: String - string to search in"},{"name":"substring","type":"String","optional":false,"default":null,"description":"substring to find","types":["String"],"since":null,"text":"substring: String - substring to find"},{"name":"indexStart","type":"Number","optional":false,"default":null,"description":"zero-based index which defines where find starts from","types":["Number"],"since":null,"text":"indexStart: Number - zero-based index which defines where find starts from"}],"returns":{"type":"Number","types":["Number"],"description":"zero-based position of the first sequence of characters that matches substring, -1 if not found","text":"Number - zero-based position of the first sequence of characters that matches substring, -1 if not found"},"form":"binary","operator":null,"left":{"text":"string","types":["String"]},"right":{"text":"[substring, indexStart]","types":["Array"]}}],"examples":[{"text":"```sqf\n[\"Apples\", \"Oranges\", \"Pears\"] find \"Oranges\"; // returns 1\n```","code":["[\"Apples\", \"Oranges\", \"Pears\"] find \"Oranges\"; // returns 1"]},{"text":"```sqf\n[1, [2], [[3]]] find [[3]]; // returns 2 - does not work in OFP, returns -1\n```","code":["[1, [2], [[3]]] find [[3]]; // returns 2 - does not work in OFP, returns -1"]},{"text":"```sqf\nif (magazines player find \"Strela\" != -1) then { hint \"You've got Strela!\"; };\n```","code":["if (magazines player find \"Strela\" != -1) then { hint \"You've got Strela!\"; };"]},{"text":"```sqf\nhint str (\"japa is the man!\" find \"the man!\"); // returns 8\n```","code":["hint str (\"japa is the man!\" find \"the man!\"); // returns 8"]},{"text":"```sqf\n\"abc\" find \"\"; // returns 0\n```","code":["\"abc\" find \"\"; // returns 0"]},{"text":"```sqf\n\"abcdefghijklmnopqrstuvxyz\" find \"z\"; // returns 24\n\"abcdefghijklmnopqrstuvxyz\" find [\"z\", 20]; // returns 24, better performance\n```","code":["\"abcdefghijklmnopqrstuvxyz\" find \"z\"; // returns 24\n\"abcdefghijklmnopqrstuvxyz\" find [\"z\", 20]; // returns 24, better performance"]},{"text":"```sqf\n\"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\n```","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"]}],"multiplayer":null,"problems":null,"aliases":[],"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```"}],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Arrays","Command Group: Strings","Introduced with Operation Flashpoint: Elite version 1.00","Operation Flashpoint: Elite: New Scripting Commands","Operation Flashpoint: Elite: Scripting Commands","Operation Flashpoint: Scripting Commands","Scripting Commands","Take On Helicopters: Scripting Commands"]}