REPLACE Function

The REPLACE function replaces a specified attribute, value or subvalue in an array with another expression.

Format

array = REPLACE(array, attr# [,value# [,subval#]] {,|;}expr) array < attr# [,value# [,subval#]] > = expr

Parameter(s)

array

Dynamic array to be changed.

attr#

An expression evaluating to the attribute number. The attr# may be greater than or equal to 1, or less than 0. If attr# evaluates to a negative number, a new attribute with the new data is appended to the end of the array. If attr# evaluates to a number greater than the number of attributes in the array, a new attribute with the new data is appended to the end of the array, with the correct number of empty attributes inserted.

value#

An expression evaluating to the value number. If value# is omitted or equal to 0, the entire contents of the attribute is replaced. If value# evaluates to a negative number, a new value with the new data is appended to the end of the attribute. If value# evaluates to a number greater than the number of values in the attribute, a new value with the new data is appended to the end of the attribute, with the correct number of empty values inserted.

subval#

An expression evaluating to the subvalue number. If subval# is omitted or equal to 0, the entire contents of the value are replaced. If subval# evaluates to a negative number or a number greater than the number of subvalues in the value, a new subvalue with the new data is appended to the end of the value. If subval# evaluates to a number greater than the number of subvalues in the value, a new subvalue with the new data is appended to the end of the value, with the correct number of empty subvalues inserted.

expr

String expression with which to replace the specified attribute, value, or subvalue.

Description

The REPLACE function returns a dynamic array with the specified field, value, or subvalue replaced with new data.

There are two forms of the REPLACE function listed above. The first form uses the REPLACE keyword, and the second form uses angle brackets similar to the EXTRACT angle brackets. In the first form of REPLACE, either a comma or a semicolon can delimit the subvalue expression from the replacement data, but if the subvalue is omitted, then a semicolon must be used.

If an attribute, value, or subvalue expression evaluates to a noninteger value, it is truncated to an integer value.

Example

To replace Attribute 8 of the array RECORD with the string "NEW YORK", the code would read:

RECORD = REPLACE(RECORD, 8, "NEW YORK")

or:

RECORD<8> = "NEW YORK"

In the next application the dynamic array CUST.REC has the customer’s billing information (credit card, account number, and expiration date) in Attributes 6, 7, and 8. The REPLACE function is used to change the customer’s billing information.

PRINT "YOUR CURRENT BILLING IS:" :

PRINT

PRINT "CREDIT CARD: ",CUST.REC< 6 >

PRINT "ACCOUNT NO. ",CUST.REC< 7 >

PRINT "EXPIRES",CUST.REC< 8 >

PRINT "DO YOU WANT TO CHANGE THIS (Y OR N)?":

INPUT ANSWER,1

IF ANSWER = "Y" THEN

   PRINT "CREDIT CARD: ":

   INPUT CARD

   CUST.REC< 6 > = CARD

   PRINT "ACCOUNT NO.: :

   INPUT ACCT.NO

   CUST.REC< 7 > = ACCT.NO

   PRINT "EXPIRATION DATE: ":

   INPUT EXP.DATE

   CUST.REC< 8 > = EXP.DATE

END ELSE

   .

   .

   .

END

See Also

Statement and Function Reference