Skip to content
Advertisement

How can i format the content of the mail by using MessageFormat in java

I have an automatic mail content that I want to send in java. I want to format it in java using MessageFormat.

Here is the content of the mail containing three parameters to customize.

JavaScript

These parameters will be retrieved in an array and will be inserted in the content of the mail

JavaScript

I want to display the message as in the content of the mail and how to pass my three string variables instead of {0}, {1} and {2}. How can I do this in java ?

Advertisement

Answer

You can do:

JavaScript

Note – single quote ' should be escaped by doubling the single quote: ''.

Unescaped quote:

JavaScript

Incorrect output:

JavaScript

Not what we wanted…

To fix it, we should escape the quote l'achat –> l''achat:

JavaScript

Correct output:

JavaScript
Advertisement