# String Replace

> Replace a substring with a new substring within a string.

- ID: `string_replace`
- Type: Block
- Category: [Strings](https://inventor.bot/docs/reference/blocks/strings.md)

> Leave the "Number of Replacements" blank to replace all instances.

- Value block: it can be used directly inside expressions, e.g. `"Result: " + string_replace(Args{...})`.

**Inputs**

| Name | Required | Description | Value |
| --- | --- | --- | --- |
| `text` | yes | Original string. | e.g. `"hello world"` |
| `old_substring` | yes | Substring to replace. | e.g. `"world"` |
| `new_substring` | yes | Replacement substring. | e.g. `"there"` |
| `number_of_replacements` |  | Maximum replacements to make. Leave blank for all. | e.g. `"1"` |

**Outputs**

| Name | Description | Value |
| --- | --- | --- |
| `string` | Resulting string. | e.g. `"hello there"` |

**Example**

```go
stringReplace := string_replace(Args{
	text:          "hello world",
	old_substring: "world",
	new_substring: "there",
})
send_text_message(Args{channel_id: trigger.channel_id, message_content: "String: " + stringReplace})
```