FIELDSTORE function

Syntax

FIELDSTORE (string, delimiter, start, n, new.string)

Description

Use the FIELDSTORE function to modify character strings by inserting, deleting, or replacing fields separated by specified delimiters.

string is an expression that evaluates to the character string to be modified.

delimiter evaluates to any single ASCII character, including field, value, and subvalue marks.

start evaluates to a number specifying the starting field position. Modification begins at the field specified by start. If start is greater than the number of fields in string, the required number of empty fields is generated before the FIELDSTORE function is executed.

n specifies the number of fields of new.string to insert in string. n determines how the FIELDSTORE operation is executed. If n is positive, n fields in string are replaced with the first n fields of new.string. If n is negative, n fields in string are replaced with all the fields in new.string. If n is 0, all the fields in new.string are inserted in string before the field specified by start.

If string evaluates to the null value, null is returned. If delimiter, start, n, or new.string is null, the FIELDSTORE function fails and the program terminates with a run-time error message.

Example

Q='1#2#3#4#5'
*
TEST1=FIELDSTORE(Q,"#",2,2,"A#B")
PRINT "TEST1= ",TEST1
*
TEST2=FIELDSTORE(Q,"#",2,-2,"A#B")
PRINT "TEST2= ",TEST2
*
TEST3=FIELDSTORE(Q,"#",2,0,"A#B")
PRINT "TEST3= ",TEST3
*
TEST4=FIELDSTORE(Q,"#",1,4,"A#B#C#D")
PRINT "TEST4= ",TEST4
*
TEST5=FIELDSTORE(Q,"#",7,3,"A#B#C#D")
PRINT "TEST5= ",TEST5

This is the program output:

TEST1=   1#A#B#4#5
TEST2=   1#A#B#4#5
TEST3=   1#A#B#2#3#4#5
TEST4=   A#B#C#D#5
TEST5=   1#2#3#4#5##A#B#C