Java ResourceBundle在值中占据空白 [英] Java ResourceBundle leading whitespace in values

查看:226
本文介绍了Java ResourceBundle在值中占据空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试 Oracle的文档中给出的示例。 java文件是此处,如该页面所示。现在有了这个java文件,我在同一目录中保留了一个 LabelsBundle.properties 文件。

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?

换句话说,我需要做什么来读取 s1 的值为

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

 computer

而不是

computer

推荐答案

Unicode转义序列 \ u0020 应该这样做,因为属性解析器应该将其识别为实际值,Java String应将 \ u0020 解释为空格的Unicode代码点。

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.

或者,IIRC,你可以用像他这样的反斜杠来逃避空间s \ my value 。也适用于钥匙。

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

这篇关于Java ResourceBundle在值中占据空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆