# ereplace() function

The
 ereplace() function searches a *str.exp* for
 the *search.str*. If the
 *search.str* is at the *start* occurrence,
 then *replacement.str* replaces *search.str* for
 the amount specified in
 *occurrences*.

**Synonyms:** change(), swap()

## Syntax

```
 ereplace(str.exp, search.str, replacement.str{,occurrences{,start}})
```

## Parameter(s)

| str.exp | String in which the specified search.str is searched. |
| --- | --- |
| search.str | String to search for in str.exp. |
| replacement.str | String to replace the specified search.str. |
| occurrences | Specifies the number of occurrences of search.str to be replaced by replacement.str. If not specified, the default is 0, which replaces all found occurrences. |
| start | Specifies on which occurrence of search string the replacement begins. If not specified, the default is 1. |

## Example(s)

**Example 1**

This code assigns the value `"The old time"` to `nstring`:

```

 nstring = ereplace("The new time","new","old")
```

 **Example 2**

 This code outputs `"++-"`. The ereplace()
 function replaces two occurrences of `"-"` starting at the
 first occurrence.

```

 print ereplace("---","-","+",2,1)
```

## See also

- [Statements and functions](https://d3codex.com/pickbasic-flashbasic/statements-and-functions/)
- [swap() function](https://d3codex.com/pickbasic-flashbasic/swap-function/)
- [change() function](https://d3codex.com/pickbasic-flashbasic/change-function/)

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