Substitute (open)

Search and replace parts of a string

Syntax

// Core function, no LOADLIB necessary

STRING FUNCTION Substitute(STRING text, STRING search, STRING replace)

Parameters

STRING text

String to perform the search & replace in

STRING search

Text to substitute

STRING replace

Text to subsitute 'search' with

Return value

STRING

The updated string

Description

Substitute does a case-sensitive search through the specified string, and replaces every occurrence of the searched-for text with specified replacement text. If the searched-for string is not found, the original string is returned unmodified.

Examples

// returns 'a+b+c+d+e+f'
STRING example1 := substitute("a-b-c-d-e-f", "-","+");

// returns 'a b c d e f'
STRING example2 := substitute("a-b-c-d-e-f", "-"," ");

// returns 'a-b-c-d-e-f', because search string 'g' is not found
STRING example3 := substitute("a-b-c-d-e-f", "g","h");

// returns 'a-b-c-d-e-f', because search string is empty
STRING example4 := substitute("a-b-c-d-e-f", "", "g");

// returns 'a-b-c-d-e-f', because search string 'A' is not found
STRING example5 := substitute("a-b-c-d-e-f", "A", "+");

// returns 'xyz-bcdef'
STRING example6 := substitute("abcdef", "a", "xyz-");