arrayhack(
arrayhack(
ARRAY
,
SEPARATOR
,
SEARCH
,
HACK
)

The arrayhack( function hacks an array by adding, replacing or removing array elements

Parameters

This function has four parameters:

array – the array to be hacked (see Text Arrays).

separator – the separator value for the array. Can be more than one character long.

search – a value to be searched for in the array. The function searches each array element until it finds one that contains this text. The array element doesn’t have to be the same as the text, it only has to contain the text, however, the text must match exactly, including upper and lower case.

hack – the text that will be placed into the array. By default, this text is placed just below the text found by the search parameter (or at the end of the array if there was no match).

If the first character of the hacked text is ∆ (Option-J), the text is inserted above the text found by the search parameter (or at the top of the array if there was no match). (The ∆ character itself is not included in the inserted text.)

If the first character of the hacked text is =, the array element found by the search parameter will be replaced by the hacked text. (The = character is not included.) If there was no match, no change is made to the array.

If the first character of the hacked text is ↩, or the hack text is empty, the array element found by the search parameter will be deleted from the array. If there was no match, no change is made to the array. If the ↩ character is used, you can add a number to delete additional lines above or below the matching line (see below). Note: The ↩ character cannot be generated from the keyboard, so the best way to use it is to copy it from this help file.

Note: If the hack text ends with the separator character, that character is removed before inserting the text into the array. (However, if there is more than one separator at the end, only the last one is removed.)

Description

This function takes an existing array and modifies it by adding, replacing or removing array elements. The function searches for an array element you specify, then performs one of four operations: (1) adds a new array item (or items) below the specified element, (2) adds a new array item (or items) above the specified element, (3) replaces the specified element, or (4) deletes the specified element.

Note: This function only performs one “hack” per search. If multiple array elements match the search text, only the first will be “hacked.”

#### Inserting Below an Array Element

The default operation is to add a new item (or items) below the specified element. This example inserts white after the green element.

    arrayhack("red,green,blue",",","green","white") ☞ red,green,white,blue

You don’t have to specify the entire array element. Since only one element contains the letter “g”, this example works the same as the previous one.

    arrayhack("red,green,blue",",","g","white") ☞ red,green,white,blue

If the element you are searching for doesn’t exist, the new element will be added at the end of the array.

    arrayhack("red,green,blue",",","orange","white") ☞ red,green,blue,white

#### Inserting Above an Array Element

To insert above an existing array element, add a ∆ (Option-J) character to the beginning of the new item text. This example inserts white before the green element. (Notice that the ∆ character itself is not inserted.)

    arrayhack("red,green,blue",",","green","∆white") ☞ red,white,green,blue

If the element you are searching for doesn’t exist, the new element will be inserted at the beginning of the array.

    arrayhack("red,green,blue",",","orange","∆white") ☞ white,red,green,blue

#### Replacing an Array Element

To replace an existing array element, add an `=` character to the beginning of the hack text. This example replace green with white.

    arrayhack("red,green,blue",",","green","=white") ☞ red,white,blue

Remember that you don’t have to specify the entire array element. This example also replace green with white, even though only the letter “g” was specified.

    arrayhack("red,green,blue",",","g","=white") ☞ red,white,blue

If the element you are searching for doesn’t exist, the array is left unchanged.

    arrayhack("red,green,blue",",","orange","=white") ☞ red,green,blue

#### Deleting an Array Element

To delete an existing array element, specify `""` (empty text) for the hack parameter. This example removes the green element.

    arrayhack("red,green,blue",",","green","") ☞ red,blue

Remember that you don’t have to specify the entire array element. This example also removes the green element, even though only the letter “g” was specified.

    arrayhack("red,green,blue",",","g","") ☞ red,blue

If the element you are searching for doesn’t exist, the array is left unchanged.

To delete multiple elements, use ↩ as the hack parameter, followed by a number. If the number is positive, additional elements after the matching element will be removed (whether they match or not). In this example, two elements are removed, green and blue.

    arrayhack("red,green,blue,gold,silver,bronze",",","green","↩2") ☞ red,gold,silver,bronze

If the number is negative, additional elements before the matching element will be removed. In this example, three elements will be removed: gold, blue and green.

    arrayhack("red,green,blue,gold,silver,bronze",",","gold","↩-3") ☞ red,silver,bronze

#### Inserting/Replacing Multiple Array Elements

All of the examples so far have shown inserting or replacing with single array elements. To insert/replace multiple array elements, simply include the separator character in the text to be inserted or replaced. This example inserts three colors between green and blue.

    arrayhack("red,green,blue",",","green","gold,silver,bronze") ☞ red,green,gold,silver,bronze,blue

#### Performing Multiple Hack Operations

By adding additional pairs of search/hack parameters, the arrayhack( function can perform multiple “hacks” on the same array. This example adds white after green, then adds gold after red, then changes red to pink.

    arrayhack("red,green,blue",",","g","white","r","gold","r","=pink") ☞ pink,gold,green,white,blue

See Also

- appenddataarrays( -- appends two or more data arrays to each other (see Data Arrays).
- array( -- extracts a single data item from a text array or a data array (see Text Arrays and Data Arrays).
- arrayboth -- creates a new array from two existing arrays. The new array contains only items that are in both of the original arrays.
- arrayboth( -- creates a new array from two arrays. The new array contains only items that are in both of the original arrays.
- arraybuild -- builds an array by scanning a database and creating an array element for every record (including invisible records) in the database (see Text Arrays).
- arraybuild( -- builds an array by scanning a database and creating an array element for every record (including invisible records) in the database (see Text Arrays).
- arraychange( -- changes the value of a single data item in a text array or a data array (see Text Arrays and Data Arrays).
- arraycolumn( -- extracts a column from a two dimensional array.
- arraycontains( -- checks to see if any element of a text array or a data array matches a specified value.
- arraydeduplicate( -- removes duplicate elements from a text array (see Text Arrays).
- arraydelete( -- deletes (removes) one or more elements from a text array or a data array (see Text Arrays and Data Arrays).
- arraydeletevalue( -- deletes any array elements that match the value parameter. This must be an exact match, including upper and lower case. If the value occurs multiple times in the array, every occurence of the value will be removed, with one exception: if the value occurs in two consecutive array elements, only the first occurence will be deleted.
- arraydifference -- creates a new array from two existing arrays. The new array contains only items that are in the first array but *not* in the second array.
- arraydifference( -- creates a new array from two existing arrays. The new array contains only items that are in the first array but *not* in the second array.
- arrayelement( -- converts between character positions and array element numbers in a text array.
- arrayfilter( -- processes each element of a text array or a data array with a formula (see Text Arrays and Data Arrays).
- arrayfirst( -- extracts the first element of a text array.
- arrayinsert( -- inserts one or more empty elements into the middle of a text array (see [Text Arrays]).
- arrayitemsandwich( -- adds a prefix and/or suffix to each non-blank item in a text array.
- arrayitemtrim( -- removes characters from the beginning and/or end of each item in an array.
- arraylast( -- extracts the last element of an array.
- arraylefttrim( -- removes one or more elements from the beginning of an array.
- arraylookup( -- uses a key to look up a value in a two dimensional text array containing key/value pairs (see Text Arrays).
- arraymerge( -- merges two text arrays together (see [Text Arrays]).
- arraymultisort -- sorts a two-dimensional array on the key of one or more of its columns.
- arraymultisort( -- sorts a two-dimensional array on the key of one or more of its columns.
- arraynotcontains( -- is the reverse of arraycontains(. it returns *false* if the value is in the array, *true* if it is not in the array.
- arraynumericsort( -- sorts a text array in numeric order (see Text Arrays).
- arraynumerictotal -- totals all the numeric elements of a text array.
- arraynumerictotal( -- totals all the numeric elements of a text array.
- arrayrandomize -- reorders an array in random order.
- arrayrandomize( -- reorders an array in random order.
- arrayrange( -- extracts a series of data items from a text array or a data array (see Text Arrays and Data Arrays).
- arrayrelocate -- moves one or more items in a text array to a new position.
- arrayrelocate( -- moves one or more items to a new position in a text array or a data array (see Text Arrays and Data Arrays).
- arrayreplacevalue( -- changes array elements that match a specified value.
- arrayreverse( -- reverses the order of the elements in a text array or a data array (see Text Arrays and Data Arrays).
- arrayreverselookup( -- uses a value to look up a key in a two dimensional text array containing key/value pairs (see Text Arrays).
- arraysearch( -- searches a text array or a data array (see Text Arrays and Data Arrays) to see if it contains a specific value.
- arrayselectedbuild -- builds an array by scanning a database and creating an array element for every visible (selected) record in the database (see Text Arrays).
- arrayselectedbuild( -- builds an array by scanning a database and creating an array element for every visible (selected) record in the database (see Text Arrays).
- arraysize( -- returns the number of elements in a text array or a data array (see Text Arrays and Data Arrays).
- arraysort -- sorts the elements in an array (see Text Arrays).
- arraysort( -- alphabetizes (A-Z) the elements in a text array (see [Text Arrays]).
- arraystrip -- strips blank elements from an array.
- arraystrip( -- removes any blank elements from a text array or a data array (see Text Arrays and Data Arrays).
- arraytableceiling( -- looks up a value in a double column table, similar to the table( function but from an array instead of a database.
- arraytablefloor( -- looks up a value in a double column table, similar to the table( function but from an array instead of a database.
- arraytoggle -- "toggles" a value within an array.
- arraytopythonlist( -- converts a Panorama array into a Python list.
- arraytrim( -- removes one or more elements from the end of an array.
- arrayunpropagate -- scans an array from top to bottom, removing duplicate values in a row.
- arrayunpropagate( -- scans an array from top to bottom, removing duplicate values in a row.
- chararray( -- extracts a single character from text.
- commalist( -- converts a text array (see Text Arrays) into an English list, with items separated by a comma and a space, except for the last two items which are separated by the word *and* and spaces.
- commatocr( -- converts a comma delimited array into a carriage return delimited array.
- csvtotsv( -- converts comma separated text into tab separated text.
- Data Arrays -- A numbered collection of data values.
- dataarray( -- creates a data array from one or more separate values (see Data Arrays).
- dataarrayappend( -- appends one or more values to the end of an existing array.
- dataarraybuild( -- builds a data array by scanning a database and creating an array element for every record (including invisible records) in the database (see Data Arrays).
- dataarrayinsert( -- inserts one or more values into the middle of an existing array.
- dataarrayselectedbuild( -- builds a data array by scanning a database and creating an array element for every visible record in the database (see Data Arrays).
- exportdataarray( -- converts a data array into a text array (see Data Arrays and Text Arrays).
- extract( -- extracts a single data item from a text array, and can also be used to count the number of items in the array.
- generatedataarray( -- generates a new data array based on a formula (see Data Arrays and Text Arrays).
- htmlarraytable -- generates an HTML table from an arrray.
- htmldatamerge -- uses a template to generate HTML you want from a database.
- htmldatatable -- generates an HTML table from selected data in the current database.
- htmltabletoarray -- converts an HTML table into a text array.
- importdataarray( -- converts a text array into a data array (see Data Arrays and Text Arrays).
- lineitemarray( -- converts the data in a set of line item fields into a text array (see Text Arrays).
- linescontain( -- checks to see if any line in a carriage return separated array matches the specified value.
- linesnotcontain( -- is the reverse of the linescontain( function.
- linesort( -- sorts lines of text in ascending order.
- linestrip( -- removes any blank lines from the text.
- makenumberedarray -- generates a numeric sequenced text array.
- makenumberedarray( -- generates a numeric sequenced text array.
- randomarrayelement( -- returns a random element from an array.
- randomline( -- returns a random line from multiple lines of text.
- randomword( -- returns a random word from a list of words.
- setfieldproperties -- modifies one or more properties (name, data type, formula, etc.) of the current field.
- superarraybuild -- scans a database to create a text array. This statement is is similar to arraybuild, but with a number of additional options (see Text Arrays).
- tabarray( -- extracts the nth element from a tab delimited array.
- tagarray( -- builds an array (see Text Arrays) containing the body of all the specified tags (usually HTML tags) in the text.
- Text Arrays -- A numbered collection of text values.
- tsvtocsv( -- converts tab separated text into comma separated text.
- tsvtojson( -- converts tab separated text into JSON formatted text.

History

Version | Status | Notes
10.0 | New | New in this version.