STR_SUBSTITUTE

Script Function: Replaces characters or strings within a string

Syntax

STR_SUB[STITUTE] (String, [Old] [,New])

Syntax

Description/Format

String

Alphanumeric string in which the replacement should be carried out
Format: script literal or script variable

Old

Alphanumeric string to be replaced in the string.
Format: script literal or script variable
Default value: " " 

New

Alphanumeric string to replace Old
Format: script literal or script variable
Default value: " "


Return code

String that has been created through the replacement of characters

This script function replaces a character or string within a string.

Old and New are optional and not limited. If Old is not specified as a parameter, each individual empty space is replaced by the New character or string. If New is not specified as a parameter, Old is replaced by an individual empty space.

If Old is not included in the string, this function returns the string.

This script function can also be used to delete Old from the string. For this, New must be specified with two successive quotation marks (without empty spaces).

Example

The following script replaces the string environment with the string system, resulting in the string AE system:

:SET &STRING# = STR_SUBSTITUTE("AE environment", "environment", "system")

The following example replaces character A with character B. The result BBBBB is printed in the activation report.

:SET &RET# = STR_SUBSTITUTE ("AAAAA", "A", "B")
:
PRINT &RET#

The following example replaces the string AAAAA is replaced by character B. The result B is printed in the activation report.

:SET &RET# = STR_SUBSTITUTE ("AAAAA", "AAAAA", "B")
:
PRINT &RET#

The following example replaces the string AA is replaced with the string BB. The result  BBBBA is printed in the activation report.

:SET &STR1# = "AA"
:
SET &STR2# = "BB"
:
SET &RET# = STR_SUB ("AAAAA", &STR1#, &STR2#)
:
PRINT &RET#

The following example demonstrates how to delete empty spaces from a string. The result AE is printed in the activation report.

:SET &RET# = STR_SUB ("A E", " ", "")
:
PRINT  &RET#

See also: