Tutorial

Getting Started with Macros

Macro Editor

User Interface

Menus and Toolbar

Editing Macro Statements

Expression Editor

Macro Debugging

How To

Using variables

Finding and modifying objects

Creating new page content

Asking for user input

Storing persistent data

Using binary data

Sorting objects

Macro menus

Bulleted and numbered lists

Sample Macros

Concepts

Expressions

Objects

Properties

Variables

Data Types

Arrays

Functions

Literals

Operators

Comments

Last updated on: March 19, 2023
Also available as a single HTML file

Onetastic Macro Documentation > Functions > Array Functions > Array_Splice

Array_Splice

Removes a a sequence of elements of the given array and replaces it with the given array. Numeric keys in the input array is not preseved and re-numbered from 0.

Syntax

void Array_Splice(
	Array array, 
	Numeric offset, 
	Numeric length, 
	Array replacement)

Parameters

Array array
Array to remove and replace elements from.
Numeric offset
The start offset to remove and replace elements. If non-negative, the sequence will start that far away from the beginning of the array. If negative, the sequence will start that far away from the end of the array.
Numeric length
The length of the sequence. If there aren't that many elements in the array, all the elements till the end of the array will be removed and replaced. If given as zero, no elements will be removed but the new elements will be inserted at given offset.
Array replacement
The set of elements to replace with. If this is an empty array, elements are removed only. Keys in the replacement array is ignored.

Examples

$array = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // Remove 3 elements starting at index 4, and insert (97, 98) Array_Splice($array, 4, 3, Array(97, 98)) // $array is (1, 2, 3, 4, 97, 98, 8, 9, 10) // Remove first 4 elements Array_Splice($array, 0, 4, Array()) // $array is (97, 98, 8, 9, 10) // Remove 2 elements starting at 4th element from the end (98) and insert (0, -1, -2) Array_Splice($array, -4, 2, Array(0, -1, -2)) // $array is (97, 0, -1, -2, 9, 10) // Remove last 3 elements and insert (0) Array_Splice($array, -3, 3, Array(0)) // $array is (97, 0, -1, 0) // Insert (3, 4, 5) at the beginning Array_Splice($array, 0, 0, Array(3, 4, 5)) // $array is (3, 4, 5, 97, 0, -1, 0) // Insert (7, 8, 9) at the end Array_Splice($array, Array_Length($array), 0, Array(7, 8, 9)) // $array is (3, 4, 5, 97, 0, -1, 0, 7, 8, 9)

Reference

Statements

For

ForEach

If

Else If

Else

Switch

Case

Default

While

Expression

Comment

Break

Continue

Return

Hierarchy Objects

NotebookRoot

Notebook

SectionGroup

Section

Page

Page Objects

Title

Outline

Table

Column

Row

Cell

Paragraph

Text

Image

EmbeddedFile

Tag

Other Objects

DialogBox

MacroMenu

Window

Functions

Array Functions

Color Functions

Data Store Functions

Date/Time Functions

Dialog Box Functions

Macro Execution Functions

Macro Menu Functions

Object Functions

String Functions

Window Functions