- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试通过选择格式获取用于排行榜的英文序数。
我目前的解决方案是这样的:
{0,choice,0#th|1#st|2#nd|3#rd|3<th}
并使用这是一个参数。
int pos = position % 100 >= 11 && position % 100 <= 13 ? 0 : position % 10
这很好用,但我发现您可以将 {0,ordinal}
与 ICU 一起使用。
有什么简单的方法可以让它在没有 ICU 的情况下工作吗?
最佳答案
你可以这样使用:
import android.icu.text.MessageFormat
fun toOrdinal(day: String): String {
val formatter = MessageFormat("{0,ordinal}", Locale.getDefault())
return formatter.format(arrayOf(day.toInt()))
}
你会得到这些结果:
1 -> 1st
2 -> 2nd
3 -> 3rd
4 -> 4th
6 -> (...)
关于java - 如何在没有 Android ICU 的情况下在 ChoiceFormat 中使用 "{0, ordinal}",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51583532/
来自java.text.ChoiceFormat API: setChoices(double[] limits, String[] formats): Set the choices to be u
我正在尝试使用 ChoiceFormat 显示除格式元素外还有引号的消息。使用该模式,不会打印引号,但使用编程方式(如 ChoiceFormat 的 Java 文档中所示)可以正常工作。有什么线索吗?
我有一条消息要放入 HTML 页面,我希望它对打印的内容数量敏感。 java.text.ChoiceFormat去救援,对吧? text.messages=You have {0,choice,1#o
我目前有以下 JSF: 我的属性文件包含 label.address.province=Province label.address.state=State 这很好,当国家是“美国”时,我的标签输
我目前有以下 JSF: 我的属性文件包含 label.address.province=Province label.address.state=State 这很好,当国家是“美国”时,我的标签输
我正在尝试通过选择格式获取用于排行榜的英文序数。 我目前的解决方案是这样的: {0,choice,0#th|1#st|2#nd|3#rd|3= 11 && position % 100 1st 2
我是一名优秀的程序员,十分优秀!