The FIELDSTORE() function provides delimited substring assignment.
FIELDSTORE(string, delimiter, i, n, rep.string)
The value returned by the FIELDSTORE() function is the result of the replacement.
A statement of the form
S = FIELDSTORE(S, d, i, n, rep.string)
is equivalent to the delimited substring assignment operation
S[d, i, n] = rep.string
The action of FIELDSTORE() depends on the values of i and n and the number of substrings within rep.string.
If the value of the position expression, i, is less than one, a value of one is assumed. If there are fewer than i delimited substrings present in string, additional delimiters are added to reach the required position.
If the value of the number of substrings expression, n, is positive, n substrings are replaced by the same number of substrings from rep.string. If rep.string contains fewer than n substrings, additional delimiters are inserted.
If the value of the number of substrings expression, n, is zero or negative, n substrings are deleted from string and the whole of rep.string is inserted regardless of the number of substrings that it contains.
Use of the $NOCASE.STRINGS compiler directive makes the delimiter case insensitive.
S = 1*2*3*4*5
A = FIELDSTORE(S, "*", 2, 3, "A*B")
B = FIELDSTORE(S, "*", 2, 3, "A*B*C")
C = FIELDSTORE(S, "*", 2, 3, "A*B*C*D")
D = FIELDSTORE(S, "*", 2, 0, "A*B")
E = FIELDSTORE(S, "*", 2, -3, "A*B")
This program fragment performs the FIELDSTORE() function on the string S using different values for rep.string and n. The results are