StrReplace
- Last UpdatedJul 18, 2023
- 1 minute read
Replaces a substring in a string with replacement substring.
Syntax
StrReplace(sString, sFindSubstring [, sReplaceSubstring [, sTerminators]])
sString:
The source string.
sFindSubstring:
The substring to search for.
sReplaceSubstring:
The replacement substring. If this is not specified, it defaults to an empty string, that is, the matched substring will be removed from the original string.
sTerminators:
Optional set of characters to terminate the substring. If this is not specified, it defaults to an empty string. When it is specified, the substring is only considered a match if it is enclosed by one of the characters specified by this argument.
Return Value
The replaced string.
Example
// Replaces argument "abc" with 12. Use the sTerminators for higher precision
StrReplace("func(abcde, abc)", "abc", "12"); // func(12de, 12), incorrect
StrReplace("func(abcde, abc)", "abc", "12", " ,()") // func(abcde, 12),
correct