find: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(see also)
(expanded, format, example)
Line 7: Line 7:
____________________________________________________________________________________________
____________________________________________________________________________________________


| Returns the 0 based position of the first array element that matches x, returns -1 if not found.
| Searches for an array element within array or a string within a string (since ["Arma 3","Arma3",127,126674,"Development"]). Returns the 0 based index on success or -1 if not found. Test is cASe-seNsItiVE | = Description
____________________________________________________________________________________________
 
| array '''find''' x |= Syntax
 
|p1= array: [[Array]] - array to search in |= Parameter 1


Test is case-sensitive.
|p2= x: [[Anything]] - array element to find |= Parameter 2


Note that you can not locate an array within an array using this command.|= Description
| [[Number]] - 0 based position of the first array element that matches x, -1 if not found |= Return value
____________________________________________________________________________________________


| [[Number]] <nowiki>=</nowiki> array '''find''' x |= Syntax
| s2= string '''find''' x |= Syntax


|p1= array: [[Array]] to search in |= Parameter 1
|p21= string: [[String]] - string to search in |= Parameter 1


|p2= x: [[Any Value]] except [[Array]] to search for in the array |= Parameter 2
|p22= x: [[String]] - string to find |= Parameter 2


| [[Number]] 0 based position of the first array element that matches x, -1 if not found |= Return value
| r2= [[Number]] 0 based position of the first sequence of characters that matches x, -1 if not found |= Return value
____________________________________________________________________________________________
____________________________________________________________________________________________
   
   
|x1= <code>[apples,"Oranges",PEARS] find "Oranges" .... result is 1</code> |= Example 1
|x1= <code>["Apples","Oranges","Pears"] [[find]] "Oranges"; //result is 1
|x2= <code>if ((magazines player) find "Strela" > -1) then {hint "I got a Strela"}</code> |= Example 2
[1,[2],[<nowiki>[</nowiki>3]]] [[find]] <nowiki>[</nowiki>[3]]; //result is 2</code> |= Example 1
 
|x2= <code>[[if]] ([[magazines]] [[player]] [[find]] "Strela" >= 0) [[then]] {[[hint]] "You've got Strela!"};</code> |= Example 1
 
|x3= <code>[[hint]] [[str]] ("japa is the man!" [[find]] "the man!"); //8</code> |= Example 3
____________________________________________________________________________________________
____________________________________________________________________________________________



Revision as of 20:16, 12 August 2014

-wrong parameter ("Arma") defined!-1.00
Hover & click on the images for description

Description

Description:
Searches for an array element within array or a string within a string (since ["Arma 3","Arma3",127,126674,"Development"]). Returns the 0 based index on success or -1 if not found. Test is cASe-seNsItiVE
Groups:
Uncategorised

Syntax

Syntax:
array find x
Parameters:
array: Array - array to search in
x: 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:
string find x
Parameters:
string: String - string to search in
x: 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"; //result is 1 [1,[2],[[3]]] find [[3]]; //result is 2
Example 2:
if (magazines player find "Strela" >= 0) then {hint "You've got Strela!"};
Example 3:
hint str ("japa is the man!" find "the man!"); //8

Additional Information

See also:
in ArraysetresizereverseselectintoArraytoStringforEachcountpushBack

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