Message format
Syntax
messageFormat($pattern)
Description
Constructs a message format with the specified pattern for either parse() or format() calls.
See MessageFormat.
Parameters
| MessageName | Type | Type Description | Mandatory | Default |
|---|---|---|---|---|
| pattern | Character string |
The pattern in which formatting is to take place. Placeholders can be defined ( |
yes |
Return value
Type: Subject object
A message format that can now be used for parse() or format() calls.
Examples
Simple formatting
messageFormat("Good {0}, {1}! Today we have {2} degrees.").format("Morning", "Sir", 19)
Output: "Good Morning Sir! Today we have 19 degrees."
With fill() applied directly to the format string, the same formatting can be achieved without explicitly creating a format.
"Good {0}, {1}! Today we have {2} degrees."fill("Morning", "Sir", 19)
Output: "Good Morning Sir! Today we have 19 degrees."
Formatting with format type
messageFormat("At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.").format(7, now(), "a disturbance in the Force")
Output: "At 15:36:40 on 11.10.2021, there was a disturbance in the Force on planet 7."
The date is used several times in this message and formatted accordingly using time and date.
Parse
messageFormat("Good {0}!").parse("Good Morning!")
Output: List of parse results, here ["Morning"].