Substituting text into messages
You can change the text of a message before displaying it by using replacement parameters. To use replacement parameters, enter %n (where n is an integer) for the string: parameter of the id:constName:type:string:translatable: method wherever you want to insert replacement text or any object. Then, to display a message box that contains replacement parameters, code an expression like:
(self getMRI: MsgSelect
group: #AddressMsgs)
displayReplace: #('Cancel').
The argument to displayReplace: is an array of replacement parameters, where each element corresponds to a %n in the text. In this example, the message text in the NLS Workspace - Indexed Messages window was the following:
You selected %1. Continue?
When the message is displayed, Cancel replaces the parameter %1, so that the message box looks like this:
MsgSelect dialog
You can have more than one replacement parameter in a message. For example, your message string can read You selected the %1 %2. Continue? To display the two parameters, the last statement in the expression might have the following: displayReplace: #('Cancel' 'push button').
Tip icon
Because the percent (%) character in a message always indicates replacement text, be careful when using percent characters in your message. If you need to display a percent character, use an escape character (\). Thus, rather than use This was a %1% increase., use This was a %1\% increase.
The replacement parameters are converted to strings automatically if they are not already strings. If you supply more replacement parameters than are needed, the excess parameters are ignored. If you supply fewer replacement parameters than are needed, the remaining parameters are replaced with an empty string.
Last modified date: 05/14/2020