[英]String format parameter is not working in string.xml on android
in my code i'm sending string parameter to the string.xml using this 在我的代码中,我正在使用此参数将字符串参数发送到string.xml
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.xml中,即时通讯使用此获取参数
<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. 字符串格式化程序将
%s
替换为有序列表中的值。 There is no need to number them. 无需编号。 So rather than using
%s1
and %s2
just use %s
in each place like this 因此,与其使用
%s1
和%s2
不如在每个地方都使用%s
<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.
如果只有一个参数是%s,则多个参数将是%1 $ s,%2 $ s等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.