insert: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Add v2.14's alternative syntax)
m (Remove example too)
(One intermediate revision by the same user not shown)
Line 29: Line 29:
|p21= string : [[String]]
|p21= string : [[String]]


|p22= 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.
|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
Line 65: Line 65:
"Test" insert [2, "Radio"]; // returns "TeRadiost"
"Test" insert [2, "Radio"]; // returns "TeRadiost"
"Test" insert [-1, "Radio"]; // returns "TestRadio"
"Test" insert [-1, "Radio"]; // returns "TestRadio"
"Test" insert [-2, "Radio"]; // returns "TesRadiot" - Arma 3 v2.14
"Test" insert [-99, "Radio"]; // returns "RadioTest" - Arma 3 v2.14
</sqf>
</sqf>



Revision as of 18:39, 21 March 2023

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 - 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
key: HashMapKey
value: 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)
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

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