Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape multiple “%” characters in Android

Tags:

In <string-array name="versions"> I have this beast of an entry (boiled down to a reasonable minimum to reproduce the effect):

<item>100% foo 40%bar</item> 

which produces these errors:

Multiple annotations found at this line: - error: Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute? - error: Found tag </item> where </string-array> is expected 

Adding formatted="false" doesn't change a thing.

<item>100&#37; foo 40&#37;bar</item> 

results in the same error messages. WTH?

<item>100% foo 40bar</item> <item>100 foo 40%bar</item> <item>100% foo 40%</item> 

would all work fine. Escaping it with \% is just ignored resulting in the same error. %% doesn't result in an error but I get %%.

like image 361
Giszmo Avatar asked Feb 21 '12 22:02

Giszmo


People also ask

What is the '\ n escape character?

In particular, the \n escape sequence represents the newline character. A \n in a printf format string tells awk to start printing output at the beginning of a newline.

How do you type escape characters?

Character combinations consisting of a backslash (\) followed by a letter or by a combination of digits are called "escape sequences." To represent a newline character, single quotation mark, or certain other characters in a character constant, you must use escape sequences.

How do you escape Android?

If you need to escape a character that has special meaning in Android you should use a preceding backslash. By default Android will collapse sequences of whitespace characters into a single space. You can avoid this by enclosing the relevant part of your string in double quotes.


1 Answers

The % is a reserved character in XML like <, >, etc. Use %% for each % you are using in the string resource.

like image 62
Ali Azhar Avatar answered Oct 27 '22 02:10

Ali Azhar