28
label.my.answer=My Answer

I would like to add spaces deliberately at the end of the above key (e.g. I would like to have 2 spaces at the end "My Answer ")

Currently the java.util.ResourceBundle functionality kind of trims this piece of code while retrieving the value

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
Joe
  • 14,513
  • 28
  • 82
  • 144

2 Answers2

57
label.myAnswer = My Answer\u0020\u0020

Note: identifiers with dots usually represent a hierarchy of names, and my is not a hierarchy level. You would certainly not define a Java class or a Java package of that name, would you?

Roland Illig
  • 40,703
  • 10
  • 88
  • 121
  • 3
    But you wouldnt create a package named myAnswer either... As long as the name expresses well what its for who cares? Beside of that +1 for the answer – Omnaest Jun 04 '11 at 08:03
  • 2
    For example, the Eclipse Resource Bundle Editor cares. You can configure it that it regards dots as hierarchical separators, which are then displayed in a tree. You wouldn't want to have "my" as a node in that tree. – Roland Illig Jun 04 '11 at 08:56
  • In this conext I have to say that you are right. Didnt know about this plugin so +1 for your comment for that. Unfortunately I dont find any download information about the derived Babel editor. – Omnaest Jun 04 '11 at 09:25
  • No problem. Many developers that I know just stick to the naming convention of "putting dots where I like" and don't think about the semantic implications. – Roland Illig Jun 04 '11 at 09:43
  • That solution doesn't work in Spring Boot 2.0.3.RELEASE – Maksim Kostromin Jun 27 '18 at 12:08
4

Also

label.myAnswer = My Answer\ \ 
Barett
  • 5,826
  • 6
  • 51
  • 55
  • this continues the property in the next line - not intended – Enrice Feb 26 '20 at 15:00
  • No, it doesn't: look closer. The final backslash is not at the end of the line. – Barett May 15 '20 at 16:00
  • 1
    you are correct. Actually ResourceBundle should not trim the spaces, Property files are allowed to have trailing spaces. Which however I consider bad design and equally bad practice. – Enrice Jun 03 '20 at 10:16
  • You don't need to pick on me just because you were wrong. – Barett Jun 03 '20 at 15:24