FormatString

Inserts values into specific points in an existing string and returns the updated result.

Syntax

FormatString( StringPattern, ValueList );

Parameters

Parameter Name Type Description Optional? Default Value
StringPattern String The string to which the variable values should be added. At appropriate points in this string, you can include special markers written as braces around an integer, such as {5}. In each case, the integer refers to the index of an item in the expression's ValueList argument. No n/a
ValueList String A comma-separated string containing literal values or keywords to reference in the text string. The order of items in the list is important, since it directly corresponds to the braced markers in StringPattern. No n/a

Output

A string based on the StringPattern value where the index markers are replaced with the values in ValueList.

Use Case

Here is an example of a valid StringPattern:

"Hello, my name is {0}. I work as a {1}."

Each item in the ValueList argument is given an index based on the order it appears, with the first item having an index of 0, the second having 1, the third 2, and each subsequent index incrementing by one. This index is what you need to reference using the braced markers in your StringPattern.

In the current example, the value of MyName will be inserted in the text string at the {0} marker, and the value of MyJob will be inserted at the {1} marker. So if the respective values of MyName and MyJob were "Matt" and "Chef", the string resulting from the function call would be as follows:

"Hello, my name is Matt. I work as a Chef."

You can refer to the same keyword more than once in a single FormatString call by placing duplicate markers in the StringPattern argument. The following example might be used to produce the catch-phrase of a certain fictional spy:

FormatString( "The name's {0}, James {0}.", "Surname" );