I am working on a Java based Android app which uses a custom web font to show different icons. To use the icons I have created a simple HashMap
:
Map<Integer, String> iconMaß = new HashMap<String, String>() {
{
put("help", "\ue004");
put("info", "\ue005");
...
put("search", "\u0022");
put("delete", "\u005c");
}
};
This works fine, except that using "\u005c"
and "\u0022"
is not possible. "\u0022"
represents "
and "\u005c"
is \
. It seems that compiler translates the escaped unicode character and "\"
is no valid string of course. However, using "\\u005c" does not work either, since now the first backslash escaped the second one and instead of having one unicode character I now get the string
\u005c` (sixs chars long)...
So, how to escape the unicode chars correctly?
Of course I could solve this specific problem by using \
and "
instead. However, I would like to be sure that the problem does not show up with other chars as well and I would like to know how to properly escape the unicode chars.
BTW: Using "\u005c"
and "\u0022"
in Kotlin is no problem and delivers the correct result.