Bonjour,
j'ai un problème pour afficher un apostrophe avec l'utilisation du MessageFormat. Voici mon code :
l'exécution de ce code me donne le résultat suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 public static void main(String[] args) { Object[] arguments = { new Integer(7), new Date(System.currentTimeMillis()), "a disturbance in the Force" }; String result = MessageFormat.format( "'At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.'", arguments); System.out.println(result); }
les quotes présentes au début et à la fin du message n'apparaissent pas.
Code : Sélectionner tout - Visualiser dans une fenêtre à part At 15:07:36 on {1,date}, there was {2} on planet {0,number,integer}.
J'ai regardé sur l'api http://java.sun.com/j2se/1.4.2/docs/....html#patterns et j'ai trouvé le message suivant :
Cependant n'existe-t-il pas une solution pour lui dire que le 1er attribut n'est pas un pattern mais un string ?Within a String, "''" represents a single quote. A QuotedString can contain arbitrary characters except single quotes; the surrounding single quotes are removed. An UnquotedString can contain arbitrary characters except single quotes and left curly brackets. Thus, a string that should result in the formatted message "'{0}'" can be written as "'''{'0}''" or "'''{0}'''".
Warning:
The rules for using quotes within message format patterns unfortunately have shown to be somewhat confusing. In particular, it isn't always obvious to localizers whether single quotes need to be doubled or not. Make sure to inform localizers about the rules, and tell them (for example, by using comments in resource bundle source files) which strings will be processed by MessageFormat. Note that localizers may need to use single quotes in translated strings where the original version doesn't have them.
Merci de votre aide
PoichOU
Partager