Substitute function

Syntax

Substitute(source_text, old_text, new_text)

Description

Use the Substitute function to replace every occurrence of a substring found in a string with a new substring. To replace text that occurs in a specific location in a text string use the Replace function.

Parameters

Parameter Description

source_text

A String in which you want to replace substrings.

old_text

A String equal to the substring of source_text you want to replace.

A tilde character ( ~ ) used in the old_text parameter stands for an arbitrary number of white spaces. For example, the following substitution: Substitute("2003* 0723* * * * ~", "* ~", "~") produces the result 2003~0723~~~~~, not the result 2003* 0723* * * ~.

new_text

A String with which to replace occurrences of old_text in source_text.

Returns

Returns a String resulting from replacing every occurrence of old_text found in source_text with new_text.

Example

The following example changes "Second Annual Conference" to "Third Annual Conference":

&newstr = Substitute("Second Annual Conference","Second","Third");

The next example sets &newstr to "cdcdcd":

&newstr = Substitute("ababab", "ab", "cd");

Related Topics