I have a string like this:
<string name="q_title" formatted="false">Item %d of %d</string>
I'm using it in String.format like this:
String log = String.format(getString(R.string.q_title), 100, 500);
So far I've observed no problems with the output.
However, code inspection in Android Studio gives me:
Format string 'q_title' is not a valid format string so it should not be passed to String.format
Why?
Your string should be
And code
When you have multiple arguments you need to mark them with 1$, 2$... n$. In arabian langs order is reversed, so they need to know how to change it correctly.
getString(id, args...)
perform format in itself.For those still looking for this answer, as the link that Blackbelt posted implies, the correct format for the string would be:
For percent, the following worked for me.
If you are dealing with integers replace s by d
If you need to format your strings, then you can do so by putting your format arguments in the string resource, as demonstrated by the following example resource.
In this example, the format string has two arguments: %1$s is a string and %2$d is a decimal number. Then, format the string by calling getString(int, Object...). For example:
Beware to escape all special characters
I had a problem with this string because I forgot to escape the percentage character " % " at the end .
The good escaped string was :