parseSimpleArray: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "<h3 style="display:none">Bottom Section</h3> " to "")
m (Some wiki formatting)
 
(45 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Command
{{RV|type=command


| arma3
|game1= arma3
 
|version1= 1.68
|1.68


|gr1= Strings
|gr1= Strings
Line 9: Line 8:
|gr2= Arrays
|gr2= Arrays


|descr= Converts given, formatted as simple array, [[String]] into a valid [[Array]]. Simple array is array consisting of [[Number]]s, [[String]]s, [[Boolean]]s and [[Array]]s of all of the above.
This command is almost '''4&times; faster''' than similar uncached [[call]] [[compile]] method. And because [[call]] [[compile]] is not required, it is also '''more secure''' and primarily intended for use with [[callExtension]] to parse the [[String]] output into [[Array]].


| Converts given, formatted as simple array, [[String]] into a valid [[Array]]. Simple array is array consisting of [[Number]]s, [[String]]s, [[Boolean]]s and [[Array]]s of all of the above. For example: <tt>[1,"2",true,[4,"five",false]]</tt>. The string representation of this array compatible with [[parseSimpleArray]] will be <tt>"[1,""2"",true,[4,""five"",false]]"</tt> accordingly. This command is almost '''4x faster''' than similar uncached [[call]] [[compile]] method. And because [[call]] [[compile]] is not required, it is also '''more secure''' and primarily intended for use with [[callExtension]] to parse the [[String]] output into [[Array]]. Since Arma 3 v.1.95.145925 the command will tolerate extra spaces and supports single quotes. The only recognised keywords (case '''in'''sensitive) are:
{{Feature|informative|
* <tt>true</tt> - translates into [[true]]
Since {{arma3}} v1.96 the command tolerates extra spaces and supports single quotes. The only recognised keywords (case '''in'''sensitive) are:
* <tt>false</tt> - translates into [[false]]
{{Columns|2|
* <tt>nil</tt> - translates into [[nil]]
* {{hl|true}} - translates into [[true]]
* <tt>null</tt> - translates into [[nil]]
* {{hl|false}} - translates into [[false]]
* <tt>&lt;null&gt;</tt> - translates into [[nil]]
* {{hl|nil}} - translates into [[nil]]
* <tt>any</tt> - translates into [[nil]]
* {{hl|null}} - translates into [[nil]]
* {{hl|&lt;null&gt;}} - translates into [[nil]] (''not'' [[objNull]])
* {{hl|any}} - translates into [[nil]]
}}
}}


|s1= [[parseSimpleArray]] stringArray


| '''parseSimpleArray''' stringArray
|p1= stringArray: [[String]] - string formatted as simple array


|p1= stringArray: [[String]] - string formatted as simple array
|r1= [[Array]] - valid array
 
|x1= <sqf>private _arr = parseSimpleArray "[1,2,3]";</sqf>


| [[Array]] - valid array
|x2= <sqf>
private _array1 = [1, "2", true, [4, "five", false]];
private _array2 = parseSimpleArray "[1,""2"",true,[4,""five"",false]]";
_array1 isEqualTo _array2; // true
</sqf>


|x1=<code>_arr = [[parseSimpleArray]] "[1,2,3]";</code>|=  
|x3= <sqf>
|x2= <code>_bool = [[true]];
_bool = true;
_num = 123.45;
_num = 123.45;
_str = "ok";
_str = "ok";
_arr = [1,false,"cool"];
_arr = [1, false, "cool"];
_res = [[parseSimpleArray]] [[format]] ["[%1,%2,%3,%4]", _bool, _num, [[str]] _str, [[str]] _arr];  
_res = parseSimpleArray format ["[%1,%2,%3,%4]", _bool, _num, str _str, str _arr];
// Note how _bool and _num do not need [[str]], however if used anyway, the result in this case would be identical
// note how _bool and _num do not need str, however if used anyway, the result in this case would be identical
[[hint]] [[str]] _res; // [true,123.45,"ok",[1,false,"cool"]]</code>
hint str _res; // returns [true,123.45,"ok",[1,false,"cool"]]
 
</sqf>
| [[set]], [[resize]], [[pushBack]], [[pushBackUnique]], [[select]], [[apply]], [[reverse]], [[count]], [[find]], [[in]], [[forEach]], [[deleteAt]], [[deleteRange]], [[append]], [[sort]], [[arrayIntersect]], [[callExtension]]


|seealso= [[set]] [[resize]] [[pushBack]] [[pushBackUnique]] [[select]] [[apply]] [[reverse]] [[count]] [[find]] [[in]] [[forEach]] [[deleteAt]] [[deleteRange]] [[append]] [[sort]] [[arrayIntersect]] [[callExtension]]
}}
}}
<h3 style="display:none">Notes</h3>
<dl class="command_description">
</dl>
{{GameCategory|arma3|New Scripting Commands}}
{{GameCategory|arma3|Scripting Commands}}
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
<!-- CONTINUE Notes -->
<!-- DISCONTINUE Notes -->

Latest revision as of 14:22, 29 March 2024

Hover & click on the images for description

Description

Description:
Converts given, formatted as simple array, String into a valid Array. Simple array is array consisting of Numbers, Strings, Booleans and Arrays of all of the above. This command is almost 4× faster than similar uncached call compile method. And because call compile is not required, it is also more secure and primarily intended for use with callExtension to parse the String output into Array.
Since Arma 3 v1.96 the command tolerates extra spaces and supports single quotes. The only recognised keywords (case insensitive) are:
  • true - translates into true
  • false - translates into false
  • nil - translates into nil
  • null - translates into nil
  • <null> - translates into nil (not objNull)
  • any - translates into nil
Groups:
StringsArrays

Syntax

Syntax:
parseSimpleArray stringArray
Parameters:
stringArray: String - string formatted as simple array
Return Value:
Array - valid array

Examples

Example 1:
private _arr = parseSimpleArray "[1,2,3]";
Example 2:
private _array1 = [1, "2", true, [4, "five", false]]; private _array2 = parseSimpleArray "[1,""2"",true,[4,""five"",false]]"; _array1 isEqualTo _array2; // true
Example 3:
_bool = true; _num = 123.45; _str = "ok"; _arr = [1, false, "cool"]; _res = parseSimpleArray format ["[%1,%2,%3,%4]", _bool, _num, str _str, str _arr]; // note how _bool and _num do not need str, however if used anyway, the result in this case would be identical hint str _res; // returns [true,123.45,"ok",[1,false,"cool"]]

Additional Information

See also:
set resize pushBack pushBackUnique select apply reverse count find in forEach deleteAt deleteRange append sort arrayIntersect callExtension

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