insert: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - " \| *(game[0-9]|version[0-9]|gr[0-9]|serverExec|mp|pr|descr|s[0-9]|p[0-9]{1,3}|r[0-9]|x1?[0-9]|seealso) *= +" to " |$1= ")
m (Better explained format of array when using syntax 4)
 
(16 intermediate revisions by 4 users not shown)
Line 13: Line 13:
The [[String]] variant also supports [[forceUnicode]].
The [[String]] variant also supports [[forceUnicode]].


|s1= array [[insert]] [index, [value1, value2, ...], onlyIfUnique]  
|s1= array [[insert]] [index, valuesToInsert, onlyIfUnique]  


|p1= array : [[Array]]
|p1= array : [[Array]]


|p2= index: [[Number]] - index at which the values will be inserted, -1 for append.
|p2= index: [[Number]] - index at which the values will be inserted, -1 for append, {{GVI|arma3|2.14|size= 0.75}} -2 for inserting at the second-to-last position, -3 before that, etc.


|p3= [value1, value2, ...]: [[Array]] of [[Anything]] - Values to insert at the specified index
|p3= valuesToInsert: [[Array]] of [[Anything]] - values to insert at the specified index


|p4= onlyIfUnique: [[Bool]] - Only insert if the value is unique in the array, like [[pushBackUnique]]
|p4= onlyIfUnique: [[Boolean]] - (Optional, default [[false]]) only insert if the value is unique in the array, like [[pushBackUnique]]


|r1= [[Nothing]]
|r1= [[Nothing]]
Line 29: Line 29:
|p21= string : [[String]]
|p21= string : [[String]]


|p22= index: [[Number]] - index at which the values will be inserted, -1 for append.
|p22= index: [[Number]] - index at which the values will be inserted, -1 for append


|p23= substring: [[String]] - String to insert
|p23= substring: [[String]] - string to insert


|r2= [[String]] - The new string
|r2= [[String]] - the new string


|s3= hashMap [[insert]] <nowiki>[[</nowiki>key1, value1], [key2, value2], ...] {{Since|arma3|2.04|y}}
|s3= hashMap [[insert]] [<nowiki/>[key1, value1], [key2, value2], ...]
 
|s3since= arma3 2.04


|p41= hashMap: [[HashMap]]
|p41= hashMap: [[HashMap]]


|p42= key: [[HashMapKey]]
|p42= keyN: [[HashMapKey]]


|p43= value: [[Anything]]
|p43= valueN: [[Anything]]


|r3= [[Nothing]]
|r3= [[Nothing]]


|s4= hashMap [[insert]] [splitArray, [KeysAndValues]] {{Since|arma3|2.04|y}}
|s4= hashMap [[insert]] [splitArray, [keysAndValues]]
 
|s4since= arma3 2.04


|p61= hashMap: [[HashMap]]
|p61= hashMap: [[HashMap]]


|p62= splitArray: [[Boolean]] - See ''KeysAndValues''
|p62= splitArray: [[Boolean]] - determines ''keysAndValues'' format (see ''keysAndValues''<nowiki/>'s description)


|p63= KeysAndValues: [[Array]]
|p63= keysAndValues: [[Array]] - in format depending on ''splitArray''<nowiki/>'s value:
* If ''splitArray'' is [[true]] then in format {{ic|<nowiki>[</nowiki>[key1, key2, ...], [value1, value2, ...]]}}
* [[true]] - {{hl|[<nowiki/>[key1, key2, ...], [value1, value2, ...]]}}
* If ''splitArray'' is [[false]] then {{ic|<nowiki>[</nowiki>[key1, value1], [key2, value2], ...]}} Same as alt. syntax 2
* [[false]] - {{hl|[<nowiki/>[key1, value1], [key2, value2], ...]}} (same as {{Link|#Syntax 3}}, see {{Link|#Example 3}} for the correct format)


|r4= [[Nothing]]
|r4= [[Nothing]]


|x1= <code>"Test" [[insert]] [0, "Radio"]; {{cc|Returns "RadioTest"}}</code>
|x1= <sqf>
"Test" insert [0, "Radio"]; // returns "RadioTest"
"Test" insert [2, "Radio"]; // returns "TeRadiost"
"Test" insert [-1, "Radio"]; // returns "TestRadio"
</sqf>
 
|x2= <sqf>
private _array = ["a", "b", "c"];
_array insert [0, ["w"]]; // _array is now ["w", "a", "b", "c"]
 
private _array = ["a", "b", "c"];
_array insert [-1, ["w"]]; // _array is now ["a", "b", "c", "w"]
 
private _array = ["a", "b", "c"];
_array insert [-2, ["w"]]; // _array is now ["a", "b", "w", "c"] // Arma 3 v2.14
</sqf>
 
|x3= <sqf>
// Notice how the size of the right array changes depending on the format of keysAndValues format
private _map = createHashMap;
_map insert [false, ["one", 1]];
 
private _map = createHashMap;
_map insert [true, ["one"], [1]];
</sqf>
 


|seealso= [[HashMap]]
|seealso= [[HashMap]] [[pushBack]] [[pushBackUnique]] [[append]] [[+]] [[merge]]
}}
}}

Latest revision as of 11:41, 27 October 2024

Hover & click on the images for description

Description

Description:
Inserts multiple values into Array/String/HashMap.
The String variant also supports forceUnicode.
Groups:
HashMapArraysStrings

Syntax 1

Syntax:
array insert [index, valuesToInsert, onlyIfUnique]
Parameters:
array : Array
index: Number - index at which the values will be inserted, -1 for append, Arma 3 logo black.png2.14 -2 for inserting at the second-to-last position, -3 before that, etc.
valuesToInsert: Array of Anything - values to insert at the specified index
onlyIfUnique: Boolean - (Optional, default false) only insert if the value is unique in the array, like pushBackUnique
Return Value:
Nothing

Syntax 2

Syntax:
string insert [index, substring]
Parameters:
string : String
index: Number - index at which the values will be inserted, -1 for append
substring: String - string to insert
Return Value:
String - the new string

Syntax 3

Syntax:
hashMap insert [[key1, value1], [key2, value2], ...]
Parameters:
hashMap: HashMap
keyN: HashMapKey
valueN: Anything
Return Value:
Nothing

Syntax 4

Syntax:
hashMap insert [splitArray, [keysAndValues]]
Parameters:
hashMap: HashMap
splitArray: Boolean - determines keysAndValues format (see keysAndValues's description)
keysAndValues: Array - in format depending on splitArray's value:
  • true - [[key1, key2, ...], [value1, value2, ...]]
  • false - [[key1, value1], [key2, value2], ...] (same as Syntax 3, see Example 3 for the correct format)
Return Value:
Nothing

Examples

Example 1:
"Test" insert [0, "Radio"]; // returns "RadioTest" "Test" insert [2, "Radio"]; // returns "TeRadiost" "Test" insert [-1, "Radio"]; // returns "TestRadio"
Example 2:
private _array = ["a", "b", "c"]; _array insert [0, ["w"]]; // _array is now ["w", "a", "b", "c"] private _array = ["a", "b", "c"]; _array insert [-1, ["w"]]; // _array is now ["a", "b", "c", "w"] private _array = ["a", "b", "c"]; _array insert [-2, ["w"]]; // _array is now ["a", "b", "w", "c"] // Arma 3 v2.14
Example 3:
// Notice how the size of the right array changes depending on the format of keysAndValues format private _map = createHashMap; _map insert [false, ["one", 1]]; private _map = createHashMap; _map insert [true, ["one"], [1]];

Additional Information

See also:
HashMap pushBack pushBackUnique append + merge

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