LISTSERV Maestro 11.0-19 Help Table Of Contents

Calculation Formulas

Back to Calculation Formulas Overview
Back to Functions Overview


Function "ToString"

ToString(arg)

ToString(set)

Function: Returns the given argument (or set) as text (or set of texts, if a set was supplied as argument).

Return-Type: Text or Text Set

Arguments:
arg - Single Argument or Set: If a single argument is given, then this argument is converted to a text and returned. If a set of arguments is given, then all arguments in the set are converted to texts and a set with these texts is returned.

Examples:
ToString(17)
ToString(SetOf(1,23,43))


Special Feature - Unquoted String Literal:
The ToString function has a special feature that allows you (within limits) to specify a string literal in a formula without using the quote characters. Normally, a string literal must always be enclosed in quotes, like this: "literal". This can be problematic if the formula is supposed to be used in a context where quotes cannot be used. In such a situation, you can use the ToString function to specify a string literal without using quotes.

To do so, simply specify the literal as the unquoted argument for the function, like this: ToString(literal).

When the ToString function has an argument that is such an unquoted string literal, and that argument can also not be interpreted as a number, merge field name, nested formula, value set or a function call, then the ToString function will interpret the whole argument (i.e. all characters between the opening and closing parentheses) as the unquoted string literal.

Example:
ToString(Sample Literal) is equivalent to the string literal "Sample Literal"

This includes even leading or trailing whitespace.

Example:
ToString(  Sample  ) is equivalent to the string literal "  Sample  "

This has some obvious limits:
Any string that is recognized as a merge field name or a function name, or that otherwise already has a reserved or special meaning in a formula, cannot be specified as such an unquoted string literal. You have to specify it as a proper quoted string literal or use the workaround described in the example below.
The unquoted literal cannot contain the closing parenthesis, as that would terminate the literal (and the ToString function) prematurely.
And of course the unquoted literal must not contain any quote characters anywhere, not even in the middle of the string. (This would not make sense anyway, as this unquoted string literal feature is meant explicitly to be used in situations where quotes are not allowed, so having a quote somewhere in the literal would be counter productive.)

Examples:
ToString(Max) does not work, because Max is a known function. You have to write this literal as "Max", or you can trick your way around this limitation by concatenating two unquoted string literals that are both, in turn, no known function names, like this: ToString(M) + ToString(ax)

ToString(abc"def) does not work, because it contains a quote character in the literal. You have to write this literal as "abc""def" and there is also no workaround to specify it in an unquoted way with the ToString function.

© 2002-2023 L-Soft Sweden AB. All rights reserved.