find: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "|PARAMETER1= |p22=" to "|PARAMETER21= |p22=")
(Add OFP 1.99 and fix syntax and examples)
Line 5: Line 5:


|1.00|Game version=
|1.00|Game version=
|game2= ofp |Game2 name=
|version2= 1.99 |Game2 version=
____________________________________________________________________________________________
____________________________________________________________________________________________


| Searches for an array element within array or a string within a string. Returns the 0 based index on success or -1 if not found.  
| Searches for an array element within array or a string within a string. Returns the 0 based index on success or -1 if not found.
{{Important|Search is cASe-seNsItiVE!}} |DESCRIPTION=
{{Important | Search is cASe-seNsItiVE!}} |DESCRIPTION=
____________________________________________________________________________________________
____________________________________________________________________________________________


| array '''find''' x |SYNTAX=
| array [[find]] element |SYNTAX=


|p1= array: [[Array]] - array to search in |PARAMETER1=
|p1= array: [[Array]] - array to search in |PARAMETER1=


|p2= x: [[Anything]] - array element to find |PARAMETER2=
|p2= element: [[Anything]] - array element to find |PARAMETER2=


| [[Number]] - 0 based position of the first array element that matches x, -1 if not found |RETURNVALUE=
| [[Number]] - 0 based position of the first array element that matches x, -1 if not found |RETURNVALUE=


| s2= string '''find''' x           ''(since ["Arma 3","Arma3",127,126674,"Development"])''|SYNTAX2=
|s2= bigString [[find]] smallString        ''(since {{arma3}} v1.27.126674)'' |SYNTAX2=


|p21= string: [[String]] - string to search in |PARAMETER21=
|p21= bigString: [[String]] - string to search in |PARAMETER21=


|p22= x: [[String]] - string to find |PARAMETER2=
|p22= smallString: [[String]] - string to find |PARAMETER22=


| r2= [[Number]] - 0 based position of the first sequence of characters that matches x, -1 if not found |RETURNVALUE=
|r2= [[Number]] - 0 based position of the first sequence of characters that matches x, -1 if not found |RETURNVALUE2=
____________________________________________________________________________________________
____________________________________________________________________________________________
   
   
|x1= <code>["Apples","Oranges","Pears"] [[find]] "Oranges"; //result is 1
|x1= <code>["Apples", "Oranges", "Pears"] [[find]] "Oranges"; {{cc|returns 1}}</code> |EXAMPLE1=
[1,[2],[<nowiki>[</nowiki>3]]] [[find]] <nowiki>[</nowiki>[3]]; //result is 2</code> |EXAMPLE1=
 
|x2= <code>[1, [2], [<nowiki/>[3]]] [[find]] [<nowiki/>[3]]; {{cc|returns 2 - does not work in OFP}}</code> |EXAMPLE2=


|x2= <code>[[if]] ([[magazines]] [[player]] [[find]] "Strela" >= 0) [[then]] {[[hint]] "You've got Strela!"};</code> |EXAMPLE1=
|x3= <code>[[if]] ([[magazines]] [[player]] [[find]] "Strela" >= 0) [[then]] { [[hint]] "You've got Strela!"; };</code> |EXAMPLE3=


|x3= <code>[[hint]] [[str]] ("japa is the man!" [[find]] "the man!"); //8</code> |EXAMPLE3=
|x4= <code>[[hint]] [[str]] ("japa is the man!" [[find]] "the man!"); {{cc|returns 8}}</code> |EXAMPLE4=
____________________________________________________________________________________________
____________________________________________________________________________________________


| [[set]], [[resize]], [[reverse]], [[select]], [[in]], [[toArray]], [[toString]], [[forEach]], [[count]], [[pushBack]], [[pushBackUnique]], [[apply]], [[deleteAt]], [[deleteRange]], [[append]], [[sort]], [[param]], [[params]], [[arrayIntersect]], [[splitString]], [[joinString]]  |SEEALSO=
| [[set]], [[resize]], [[reverse]], [[select]], [[in]], [[toArray]], [[toString]], [[forEach]], [[count]], [[pushBack]], [[pushBackUnique]], [[apply]], [[deleteAt]], [[deleteRange]], [[append]], [[sort]], [[param]], [[params]], [[arrayIntersect]], [[splitString]], [[joinString]]  |SEEALSO=
}}
}}


Line 48: Line 52:


<h3 style="display:none">Bottom Section</h3>
<h3 style="display:none">Bottom Section</h3>
[[Category:Scripting Commands|FIND]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands OFP 1.99|FIND]]
[[Category:Scripting Commands OFP 1.99|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA|FIND]]
[[Category:Scripting Commands ArmA|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_Variables|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_Variables|{{uc:{{PAGENAME}}}}]]


<!-- CONTINUE Notes -->
<!-- CONTINUE Notes -->
Line 69: Line 73:
[[hintSilent]] [[str]] ([[isNil]] "_result"); //true</code>
[[hintSilent]] [[str]] ([[isNil]] "_result"); //true</code>
</dd>
</dd>
</dl>
<!-- DISCONTINUE Notes -->


<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on April 10, 2015 - 17:01 (UTC)</dd>
<dd class="notedate">Posted on April 10, 2015 - 17:01 (UTC)</dd>
<dt class="note">[[User:Kenoxite|Kenoxite]]</dt>
<dt class="note">[[User:Kenoxite|Kenoxite]]</dt>
<dd class="note">
<dd class="note">
'''Find''' doesn't work with multidimensional arrays in OFP/CWA. It will always returns -1.
[[find]] doesn't work with multidimensional arrays in OFP/CWA. It will always returns -1.
</dd>
</dd>
</dl>
<!-- DISCONTINUE Notes -->


<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on May 17, 2016 - 14:21 (UTC)</dd>
<dd class="notedate">Posted on May 17, 2016 - 14:21 (UTC)</dd>
<dt class="note">[[User:BaerMitUmlaut|BaerMitUmlaut]]</dt>
<dt class="note">[[User:BaerMitUmlaut|BaerMitUmlaut]]</dt>
Line 95: Line 91:
-> 5</code>
-> 5</code>
</dd>
</dd>
</dl>
<!-- DISCONTINUE Notes -->


<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on July 7, 2016 10:56 (UTC)</dd>
<dd class="notedate">Posted on July 7, 2016 10:56 (UTC)</dd>
<dt class="note">[[User:Jtgibson|Jtgibson]]</dt>
<dt class="note">[[User:Jtgibson|Jtgibson]]</dt>

Revision as of 00:53, 21 September 2019

-wrong parameter ("Arma") defined!-1.00Logo A0.png1.99
Hover & click on the images for description

Description

Description:
Searches for an array element within array or a string within a string. Returns the 0 based index on success or -1 if not found.
Search is cASe-seNsItiVE!
Groups:
Uncategorised

Syntax

Syntax:
array find element
Parameters:
array: Array - array to search in
element: Anything - array element to find
Return Value:
Number - 0 based position of the first array element that matches x, -1 if not found

Alternative Syntax

Syntax:
bigString find smallString        (since Arma 3 v1.27.126674)
Parameters:
bigString: String - string to search in
smallString: String - string to find
Return Value:
Number - 0 based position of the first sequence of characters that matches x, -1 if not found

Examples

Example 1:
["Apples", "Oranges", "Pears"] find "Oranges"; // returns 1
Example 2:
[1, [2], [[3]]] find [[3]]; // returns 2 - does not work in OFP
Example 3:
if (magazines player find "Strela" >= 0) then { hint "You've got Strela!"; };
Example 4:
hint str ("japa is the man!" find "the man!"); // returns 8

Additional Information

See also:
setresizereverseselectintoArraytoStringforEachcountpushBackpushBackUniqueapplydeleteAtdeleteRangeappendsortparamparamsarrayIntersectsplitStringjoinString

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note

Notes

Bottom Section

Posted on January 4, 2015 - 09:38 (UTC)
Heeeere's Johnny!
Using nil on either side of find will make the whole statement return Nothing: _array = [1,2,nil,4,5]; _result = _array find nil; hintSilent str (isNil "_result"); //true _result = nil find 1; hintSilent str (isNil "_result"); //true
Posted on April 10, 2015 - 17:01 (UTC)
Kenoxite
find doesn't work with multidimensional arrays in OFP/CWA. It will always returns -1.
Posted on May 17, 2016 - 14:21 (UTC)
BaerMitUmlaut
This command is unreliable/broken when it comes to some non-ASCII characters (as of Arma 3 1.58): "abcßdef" find "c" -> 2 "abcßdef" find "ß" -> 3 "abcßdef" find "d" -> 5
Posted on July 7, 2016 10:56 (UTC)
Jtgibson
Not quite unreliable, just unexpected! Strings are tracked in terms of bytes rather than in actual character positions; all strings are stored in UTF-8 format. In other words, the eszett character is in Unicode, which takes up two bytes rather than one as it is within the 128-255 range of Unicode. (Similar results would be expected for the division symbol, the umlaut, accented e's, etc.) Symbols that are particularly high in the Unicode range may take up three bytes, or even four for the truly exceptional characters, although Arma 3's default fonts are unlikely to render them. This definitely complicates any script which assumes any printable character is a single byte, however, and unfortunately I'm not skilled enough with internationalisation to recommend any robust fix.