Substitute()
Summary
Replaces a matching substring with a new string.
Syntax
new_string = Substitute(string input_str, string find_str, string repl_str, integer n)
| Argument | Contents |
|---|---|
| input_str | The input string |
| find_str | The substring to be located and replaced |
| repl_str | The new substring that is to replace the find_str substring |
| n | A number indicating which occurrence of find_str is to be replaced. If omitted (null), then all occurrences are replaced |
Returns
A string where the n-th occurrence of find_str is replaced with repl_str. If n is omitted, all occurrences of find_str are replaced.
Notes
-
If find_str is not found, or if n is larger than the number of occurrences of find_str, then the return string will be identical to the input string.
Example
s = Substitute("input string", "in", "out", 1) // s = "output string"
s = Substitute("input string", "in", "out", ) // s = "output stroutg"
See Also
| Function | Summary |
|---|---|
| Position() | Returns the position of a substring within a string |
| PositionFrom() | Search for the first occurrence of a substring within a string, starting the search at a designated position |
| PositionTo() | Search for the last occurrence of a substring within a string, ending the search at a designated position |
| SubstituteChars() | Returns the input string with all occurrences of the characters listed in the find string replaced with the characters in the replacement string |
| Substring() | Extracts a portion of a string |