INSERT( ) function

Returns the original string contents with a specified string inserted in a specified location.

Syntax

INSERT(string, insert_text, location)

Parameters

string

Character. The value to insert the text into.

insert_text

Character. The value to insert into string.

location

Numeric. The byte position where the insert_text value will be inserted into string.

Output

Character.

Remarks

This function inserts characters or spaces into a character string, in any position. If the location parameter value is greater than the length of the string parameter, the insert_text parameter value is inserted at the end of string. If location is 0 or 1, insert_text is inserted at the beginning of string. If you are specifying double quotes in insert_text, you must enclose them in single quotes (i.e., ‘”’).

The INSERT( ) function can be used to normalize data for formatting, for duplicate matching, and for the JOIN and DEFINE RELATION commands, which require identical fields. For example, part numbers in one file may be in the format “12345”, and in another file, “12-345.” You can use INSERT( ) to insert a hyphen (-) in position 3.

Examples

Example Return value

INSERT("abcde", "XXX", 2)

“aXXXbcde”

INSERT("abcde", "XXX", 8)

“abcdeXXX”

INSERT("abcde", "XXX", 0)

“XXXabcde”

INSERT(“6543”, “BCD”, 6)

“6543BCD”

Because “6543” is only 4 bytes long, “BCD” is inserted at byte position 5 instead of 6.



(C) 2013 ACL Services Ltd. All Rights Reserved. | Send feedback