Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java ResourceBundle leading whitespace in values

I'm trying out the example given at Oracle's documentations. The java file is here as shown in that page. Now with this java file, I keep a LabelsBundle.properties file in the same directory.

# This is the default LabelsBundle.properties file s1 = computer s2 = disk s3 = monitor s4 = keyboard 

it seems that the trailing whitespace is not ignored while reading the values and the leading whitespaces are ignored.

So if I want leading spaces to be there, what do I do?

In other words, what do I need to do to read the value of s1 as

 computer 

instead of

computer 

?

like image 257
prongs Avatar asked May 28 '12 10:05

prongs


2 Answers

A Unicode escape sequence \u0020 should do it, because the properties parser should recognise it as an actual value and the Java String should interpret \u0020 as the Unicode code point for space.

Alternatively, IIRC, you can escape the space with a backslash like this \ my value. Works for keys, too.

like image 168
user268396 Avatar answered Sep 21 '22 21:09

user268396


You can escape space with backlash:

s1 =\ computer 
like image 21
Mikita Belahlazau Avatar answered Sep 18 '22 21:09

Mikita Belahlazau