Did you guys (ATG/Java) come across to escape first '=' for a properties file's Map?
I have one map in my properties file like this:
elementToPropertyMap=\
./Name/Value[@locale\='en']=displayName
Here, what I want first equal should ignore ie
Key = ./Name/Value[@locale\='en'] and value = displayName
I tried these variations and but didn't get the required output.
1 ./Name/Value[@locale\='en']=displayName ./Name/Value[@locale\
2 ./Name/Value[@locale\\='en']=displayName ./Name/Value[@locale\\
3 ./Name/Value[@locale//='en']=displayName ./Name/Value[@locale//
4 ./Name/Value[@locale\=\'en']=displayName ./Name/Value[@locale\
5 ./Name/Value[@locale\\=\\'en']=displayName ./Name/Value[@locale\\
6 ./Name/Value[@locale/\=/\'en']=displayName ./Name/Value[@locale/\
7 ./Name/Value[@locale\u003d'en']=displayName ./Name/Value[@locale\u003d'en']
Yes, we can you {0} and replace with ''=" or use unicode in properties and convert its value.
But wanted to know is there default way to escape first equal.
Thanks,
Why not try it out - the other way around? I took the key which has a backslash before the =
. So that becomes \\\\
.
Properties properties = new Properties();
properties.setProperty("./Name/Value[@locale\\='en']", "displayName");
properties.setProperty("./Name/Value[@locale='en']", "displayName");
properties.store(Files.newOutputStream(Paths.get("test.properties")), "Test");
Gives a test.properties:
#Test
#Wed Jul 12 14:48:19 CEST 2017
./Name/Value[@locale\\\='en']=displayName
./Name/Value[@locale\='en']=displayName
The explanation is that =
and the backslash itself, as part of the key must be escaped. (Also :
would have need of escaping.) So two additional backslashes.
\=
is the exactly the same as an equal sign and has no effect.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.