Im using strings with placeholder in my strings.xml
<string name="date">%1$d.%2$d.%3$d</string>
And set it in the code like:
String.format(context.getResources().getString(R.string.date), day, month, year);
If we take the 5th may for example the result now is:
5.5.2015
How can i add the leading zero for numbers smaler than ten to the string resources?
Not a duplicate of Left padding a String with Zeros since the solution of this question is:
String.format("%010d", Integer.parseInt(mystring));
But the format for the android resource string is:
%1$d
where the 1
indicates the index. Where should i put the 02
?
You can use this format:
<string name="date">%1$02d.%2$02d.%3$d</string>
For further studying about format, see Formatter's sections: conversion, flags and width.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With