Arbortext Command Language > Functions by Alphabetical Listing > varsub
  
varsub
string=varsub (string)
This function substitutes variable names within a string. This function is quite useful for delaying the substitution of variables until after a call to amo_text or agettext functions.
Example
* 
This example uses agettext to retrieve a message from the default message file. Use amo_text to retrieve a localized message from a user-defined message file.
You need to display the following message from the default message file.
Error: No file named $name exists.
The problem is that the message includes a variable, $name, containing the file name test.sgm. The message is listed in the catalog with the variable name in place. Let's assume you execute agettext as follows:
msg_string = agettext \
("Error: No file named $name exists.")
The actual string passed to agettext would include the substituted value for the $name variable:
Error: No file named test.sgm exists.
This does not match the listing in the catalog, so the agettext would fail. Executing agettext within varsub solves this problem (note the use of single quotes).
msg_string = varsub(agettext \
('Error: No file named $name exists.')
In the sample above, the actual string passed to agettext would be:
Error: No file named $name exists.
This entry matches the entry in the default message file, so the returned message (variable name in place) is passed to varsub, which performs the variable substitution. The final result, stored in the variable msg_string would be:
Error: No file named test.sgm exists.
If the string includes a variable name that you do not want substituted, include an extra dollar sign ($) for the non-substituted variable. For example:
msg_string = varsub('The $$name variable is equal to $name.')
In this example, the result stored in msg_string would be:
The $name variable is equal to test.sgm.