STR_SUBSTITUTE_VAR, STR_SUB_VAR

Script function: Replaces script variable names by their values.

Syntax

STR_SUB[STITUTE]_VAR (Variables)

Syntax

Description/Format

Variables

Script variable or string that includes one or several variable names.
Format: script literal or script variable


Return code

String with the script variable's values.

The script variable STR_SUB_VAR can be used to replace one or several script variable names that are stored as a string in a different script variable by the actual variable value. The following examples illustrate this behavior.

Tip:Use the GET_PROCESS_LINE script function with the STR_SUB[STITUTE]_VAR parameter to make the same kind of replacements in data sequence lines. For more information, see GET_PROCESS_LINE.

Examples

The following example stores a script variable's name (&VAR#) in a different variable (&VAR_NOSUB#) by using the & character twice.

If &VAR_NOSUB# is output, the name of the script variable &VAR# is written to the activation report. The script element STR_SUB_VAR serves to replace this name by the variable's value.

:SET &VAR#"script variable"
:SET &VAR_NOSUB#"&&VAR# = &VAR#"
:PRINT &VAR_NOSUB#
:SET &VAR_SUB#STR_SUB_VAR(&VAR_NOSUB#)
:PRINT &VAR_SUB#

Output in the activation report:

2011-05-06 10:34:04 - U0020408 &VAR# = script variable
2011-05-06 10:34:04 - U0020408 script variable = script variable

The second example retrieves a value from the VARA object VARA.SUB which includes the names of two script variables. These two script variables are created and set.

Only the script variable names are written to the report if the VARA object's value is directly output. They are not replaced by their values.

The script element STR_SUB_VAR is used to replace the names of the two script variables by their values.

:SET &VARA# = GET_VAR(VARA.SUB, "SUBVAR")
:SET &VAR1# = "Hello"
:SET &VAR2# = "World"
:PRINT "Content without replacements: &VARA#"
:SET &VARA_SUB_VAR# = STR_SUB_VAR(&VARA#)
:PRINT "Content with replacements: &VARA_SUB_VAR#"

Output without and with STR_SUB_VAR:

2011-05-06 10:34:04 - U0020408 Content without replacements: &VAR1# &VAR2#
2011-05-06 10:34:04 - U0020408 Content with replacements: Hello World

Example

See also:

seealso

Script Elements for Editing Strings