---
updatedAt: 2025-05-20T20:28:56.000Z
agentTools:
  projectIndex: https://docs.documotor.com/llms.txt
---

# replace

Replace parts of strings

# Definition

`string replace(string $input, string $old, string $new)`

Replaces occurrences of `$old` within `$input` with `$new` and return the resulting string.

# Parameters

<Glossary>string</Glossary> `$input`

String to replace substrings in.

<Glossary>string</Glossary> `$old`

Substring of `$input` to be replaced.

<Glossary>string</Glossary> `$new`

String to replace the occurrences of `$old` within `$input` with.

# Returns

<Glossary>string</Glossary>

`$input` with all the occurrences of `$old` replaced with `$new`.

# Examples

```text Transformation
{
  a: replace('This is wrong!', 'wrong', 'correct'),
  b: replace('Line1\nLine2', '\n', ''),
  c: replace('-Hyphenated-String-', '-', `null`)
}
```

```json Result
{
  "a": "This is correct!",
  "b": "Line1Line2",
  "c": "HyphenatedString"
}
```

> 🚧 When replacing new line symbols from sample data, use \`"\n"\` to signify them instead of '\n'.