---
title: "strReplace"
canonical: "https://help.vicon.com/space/Shogun17/13537539/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

|  |
| --- |
| `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/Shogun17/pages/13537533)
- [strFind](https://vicon-help.atlassian.net/wiki/spaces/Shogun17/pages/13537531)
- [strLeft](https://vicon-help.atlassian.net/wiki/spaces/Shogun17/pages/13537545)
- [strLength](https://vicon-help.atlassian.net/wiki/spaces/Shogun17/pages/13537543)
- [strMid](https://vicon-help.atlassian.net/wiki/spaces/Shogun17/pages/13537541)
- [strReverseFind](https://vicon-help.atlassian.net/wiki/spaces/Shogun17/pages/13537497)
- [strRight](https://vicon-help.atlassian.net/wiki/spaces/Shogun17/pages/13537495)
- [strTok](https://vicon-help.atlassian.net/wiki/spaces/Shogun17/pages/13537493)
- [strTokArray](https://vicon-help.atlassian.net/wiki/spaces/Shogun17/pages/13537491)