---
title: "strReplace"
canonical: "https://help.vicon.com/space/ShogunPost121/1253736842/strReplace"
format: markdown
---
# Description

Replaces all instances of a sub-string within a string with another string, and returns the resulting string.

The search for `subStringOld` is case-sensitive.` subStringOld` and `subStringNew` do not have to be the same length.

To remove all occurrences of `subStringOld`, make `subStringNew` an empty string ("") .

## Functional area

String

# Command syntax

## Syntax

> Macro (scroll-tablelayout)

|  |
| --- |
| `strReplace "string" "subStringOld" "subStringNew"` |

### Arguments

> Macro (scroll-tablelayout)

| Name | Type | Required | Comments |
| --- | --- | --- | --- |
| `string` | string | yes | String to replace sub-strings in. |
| `subStringOld` | string | yes | Sub-string to be replaced in string. Can be1 or more characters in length. |
| `subStringNew` | string | yes | String to replace all instances of `subStringOld` in string. Can be 0 or more characters in length. |

### Flags

None

## Return value

string

Returns a new string with the old values replaced with new. 

> Macro (scroll-pagebreak)

## Examples

```plaintext
// Demonstrate usage of strReplace
string $str = "This is some text";
string $newStr;
 
// Replace "some" with "a bit of"
$newStr = `strReplace $str "some" "a bit of"`;
print $newStr; 
// Should be "This is a bit of text"
 
// Remove all occurrences of "i" in the new string
$newStr = `strReplace $newStr "i" ""`;
print $newStr; 
// Should be "Ths s a bt of text"
 
// Replace all x's with s's
$newStr = `strReplace $str "x" "s"`;
print $newStr; 
// Should be "This is some test"
```

# Additional information

## Related commands

- [strCompare](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253736489)
- [strFind](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253737935)
- [strLeft](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253737036)
- [strLength](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253738093)
- [strMid](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253737094)
- [strReverseFind](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253737016)
- [strRight](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253736764)
- [strTok](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253739563)
- [strTokArray](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253739862)