1

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

2 Answers 2

3

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>
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

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.