Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android string resource - need to include '%' character

Tags:

string

android

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>
like image 449
pulancheck1988 Avatar asked Oct 08 '12 07:10

pulancheck1988


2 Answers

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.

like image 32
Jan Němec Avatar answered Oct 15 '22 18:10

Jan Němec


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

like image 197
Nik Reiman Avatar answered Oct 15 '22 18:10

Nik Reiman