Argument | Description | Types / Required |
number | The message number. | number
not required |
text | The base (unformatted) text for the message. | string
not required |
type | The message set to query if specifying a message number.
The default value is "user". | string
not required |
arguments | The inserted values for each % formatting placeholder. | array
not required |
- Providing a message number. By default, the message text is retrieved from user-defined messages, but by specifying the type as "system" (as opposed to "user"), message text from system messages is used.
- Providing the base text directly. If a message number is used, and does not exist, then the text is used as the base text.
Supply arguments to replace the % placeholders using an array. Each argument is sequentially inserted into the text string. Arguments can be numeric or string expressions, but the type of the argument must match the type of the receiving field in the base text.
If you want to format text from a
web view, you can also use the
sprintf-js JavaScript library.
The action returns a string containing the formatted text. The base text for messages is retrieved in the
current language, if applicable.
The action throws an exception if any of its arguments are not specified in a valid form, or if the message number does not exist in the specified message set and no message text is provided. The action also throws an exception if an insufficient number of arguments is provided, or if the type of an argument does not match the % placeholder.
List string messageArguments = "Hello", "8.0";
string formattedMessage = CS.Message.formatText(text := "%s from CSPro %0.1f!",
arguments := messageArguments);
// result: Hello from CSPro 8.0!
// format the system message 1101
const parameterMessage = CS.Message.formatText({
number: 1101,
type: "system",
text: "The parameter %s does not support %d arguments",
arguments: [
"Heron",
3
]
});
// result: The parameter Heron does not support 3 arguments