Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Properties property value - message with leading white space

I have messages in properties file and reading these properties file using spring and spring message tag,

For example I have :

key.red=Red<br>
key.blue=  blue

blue message text coming as "blue" but not as " blue". The leading white spaces are taken out by spring:message tag.

how could i retain leading space ? I appreciate any help

Thanks,
Sri

like image 830
Sri Avatar asked Dec 05 '13 18:12

Sri


People also ask

How do you add a space in properties file?

'\\' - add escape character. '\ ' - add space in a key or at the start of a value.

What does ${ mean in a properties file?

The properties files are processed in the order in which they appear on the command line. Each properties file can refer to properties that have already been defined by a previously processed properties file, using ${varname} syntax.

How do I escape the special characters in properties file?

In my case, two leading '\\' working fine for me.


1 Answers

Try doing it like this:

key.blue=\u0020blue

You can use other unicode codes to escape characters as well. All per Java API doc. Quote:

...Characters that cannot be directly represented in this encoding can be written using Unicode escapes ....

like image 180
dimoniy Avatar answered Oct 03 '22 09:10

dimoniy