Go to: Synopsis. Return value. MEL examples.

Synopsis

int stringArrayInsertAtIndex(int $index, string[] $list, string $item)

Insert $item at $index in the string array $list. If $index is greater than the last index of $list, $item will be placed at the end of the list.

Return value

None

Arguments

Variable Name Variable Type Description
$indexintThe index into $list to add $str at
$liststring[]A list of string values.
$itemstringThe new item to add to $list at $index

MEL examples

  // Initialize the list
  string $list[] = {"item1", "item3"};
  // Result: item1 item3 //
  // Insert in the middle of the sequence
  stringArrayInsertAtIndex(1, $list, "item2");
  // Result: 1 //
  print $list;
  // Result: item1 item2 item3 //
  // Insert before the first element
  stringArrayInsertAtIndex(-1, $list, "item4" );
  // Result: 0 //
  // Insert at (or after) the end of the sequence
  stringArrayInsertAtIndex( 10, $list, "item4" );
  // Result: 1 //
  print $list;
  // Result: item1 item2 item3 item4 //
  // Insert at the beginning of the sequence
  stringArrayInsertAtIndex( 0, $list, "item0" );
  // Result: 1 //
  print $list;
  // Result: item0 item1 item2 item3 item4 //