STR_SUBSTITUTE

Use the STR_SUBSTITUTE script function to replace characters or strings within a string. This script function can also be used to delete the Old parameter from the string. For this purpose, you must specify the New parameter with two successive quotation marks without any empty spaces.

Syntax

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

Parameters

  • STR_SUB[STITUTE
    Replaces characters or strings within a string

  • String
    Alphanumeric string in which a character or a string should be replaced
    Format: script literal or script variable

  • Old
    (Optional) Alphanumeric string that should be replaced in the String parameter. The length of this parameter is not limited. If the Old parameter is not used, each individual empty space is replaced by the character or string that is defined in the New parameter.
    Format: script literal or script variable
    Default: " " 

  • New
    (Optional) Alphanumeric string that should replace Old. The length of this parameter is not limited. If you do not use the New parameter, the Old parameter is replaced by an individual empty space.
    Format: script literal or script variable
    Default: " "

Return code

  • The new string that has been created through the replacement of characters.
  • If the definition of Old is not part of the String parameter, this script function returns the original string without any changes.

Example

The following script replaces the string "environment" with the string "system". The result is the new string "AE system":

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

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

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

The following example replaces the string AAAAA 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 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 you can 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: