繁体   English   中英

字符串格式参数在Android上的string.xml中不起作用

[英]String format parameter is not working in string.xml on android

在我的代码中,我正在使用此参数将字符串参数发送到string.xml

String.format(getString(R.string.notification_devil_expire_coupon_for_one_user), "iphone", String.valueOf(loggedInUser.getExpiryReminder()));

在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>

预期产量

 Do you even shop, bro? Your iphone coupon expires in 3 days.

但我的输出是

 Do you even shop, bro? Your iphone1 coupon expires in 32 days.

参数编号添加在字符串中。 我不知道我在代码中哪里做错了

字符串格式化程序将%s替换为有序列表中的值。 无需编号。 因此,与其使用%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>

对参数进行编号是一种很好的做法,因为顺序可能会根据语言而变化。 如果只有一个参数是%s,则多个参数将是%1 $ s,%2 $ s等。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM