# replace() function

The replace() function inserts or replaces
a specific attribute, value, or subvalue in the string referenced
by *dyn.array.exp* with the value referenced in
 *str.exp*.

## Syntax

```
replace(dyn.array.exp, ac.exp; str.exp)
replace(dyn.array.exp, ac.exp, vc.exp; str.exp)
replace(dyn.array.exp, ac.exp, vc.exp, sc.exp, str.exp)
```

## Parameter(s)

| dyn.array.exp | Attribute, value, or subvalue to replace with the value in str.exp. |
| --- | --- |
| ac.exp | Attribute (or, the attribute that contains the value or subvalue) that contains the specified dyn.array.exp to replace. |
| vc.exp | Value (or, the value that contains the subvalue) that contains the specified dyn.array.exp to replace. |
| sc.exp | Subvalue that contains the specified dyn.array.exp to replace. |
| str.exp | Value to replace the value specified in dyn.array.exp. |

## Description

-1 can be specified as the *ac.exp*, *vc.exp*, or *sc.exp*. This appends *str.exp* as the last element in
the respective location. If the last character of *str.exp* is not the correct separator, the appropriate mark character (attribute,
value, or subvalue) is inserted before the expression is added.

Alternate method, using dynamic array reference symbols:

```
dyn.array.exp<ac.exp {,vc.exp {,sc.exp}> = str.exp
```
CAUTION: The behavior of the replace() function with attribute 0 is undefined and should be avoided.

## Example(s)

In these examples, value 1 of
attribute 1 in the first element of the dimensioned array, `customer.item`, is replaced with the data value in the variable `name`.

```
customer.item(1) = replace(customer.item(1),1,1,0,name)
customer.item(1) = replace(customer.item(1),1,1;name)
```
 This can alternately be coded as:

```
customer.item(1)<1,1> = name
```
The statements below add a new value at the end of attribute
1 of `string`.

```
string<1,-1> = value
string = replace(string,1,-1,0,value)
string = replace(string,1,-1;value)
```

---
Source: https://d3codex.com/pickbasic-flashbasic/replace-function/ - part of the D3Codex reference.
