in my code i'm sending string parameter to the string.xml using this
String.format(getString(R.string.notification_devil_expire_coupon_for_one_user), "iphone", String.valueOf(loggedInUser.getExpiryReminder()));
in string.xml im using this to get the parameter
<string name="notification_devil_expire_coupon_for_one_user">Do you even shop, bro? Your <xliff:g id="retailer">%s1</xliff:g> coupon expires in <xliff:g id="endDate">%s2</xliff:g> days.</string>
expected output
Do you even shop, bro? Your iphone coupon expires in 3 days.
but my output is
Do you even shop, bro? Your iphone1 coupon expires in 32 days.
parameter number is added in the string. i dont know where i'm doing wrong in the code
the string formatter substitutes %s
with values in an ordered list. There is no need to number them. So rather than using %s1
and %s2
just use %s
in each place like this
<string name="notification_devil_expire_coupon_for_one_user">Do you even shop, bro? Your <xliff:g id="retailer">%s</xliff:g> coupon expires in <xliff:g id="endDate">%s</xliff:g> days.</string>
Numbering your arguments is good practice since the order may change depending on language. Where just one argument is %s, several will be %1$s, %2$s etc.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.