11

So how do I include in a string resource the '%' character?

VALID

<string name="my_string">Total discount boundary:\nmin=%1$s nmax=%2$s</string>

INVALID

<string name="my_string">Total discount boundary:\nmin=%1$s % nmax=%2$s %</string>

5 Answers 5

20

You should be able to use %% to get a percentage sign without being parsed as a string format character.

Sign up to request clarification or add additional context in comments.

1 Comment

I get %% from %% and error from % in Android Developer Studio 23.0.2. So it seems there is no such a simple solution.
1

Adding formatted="false" helped me. This

<string name="parser_error_convert" formatted="false">Parser error, line %d, \'%s\', cannot convert \'%s\'</string>

works with my strings and I expect it would help also in case of your strings. Double %% does not help because you will get %% (not %) as a result.

This problem depends on the plugin version, I am using Android Developer Studio 23.0.2.

Comments

1

If you want to include a literal "%" character in your string resource, you need to escape it using another "%" character. Here's how you can do it:

 <string name="rating">Rating: %d%%</string>

Comments

0

For me, it works just fine. I use the Eclipse Android plugin, and i can add a String containing % signs without a problem. What tool do you use ?

Comments

-2

try this

<string="my_string" format="false">bla bla bla</string>

2 Comments

Care to comment your answer? How your solution solves OP problem?
Setting format="false" is incorrect here as it will cause "%1$s" to literally be printed out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.