Java 如何使用;{0,序数}”;在没有安卓ICU的ChoiceFormat中

Java 如何使用;{0,序数}”;在没有安卓ICU的ChoiceFormat中,java,messageformat,Java,Messageformat,我试图通过choice格式获得在排行榜中使用的英文序号 我目前的解决方案是这样: {0,choice,0#th|1#st|2#nd|3#rd|3<th} {0,choice,0#th | 1 | st | 2#nd | 3 | rd | 3=11&&position%100您可以使用以下内容: import android.icu.text.MessageFormat fun toOrdinal(day: String): String { val formatter = Me

我试图通过choice格式获得在排行榜中使用的英文序号

我目前的解决方案是这样:

{0,choice,0#th|1#st|2#nd|3#rd|3<th}

{0,choice,0#th | 1 | st | 2#nd | 3 | rd | 3=11&&position%100您可以使用以下内容:

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 -> (...)

我使用了我在问题中包含的内容。我传递了一个参数。你是否将此传递到消息格式?
1 -> 1st
2 -> 2nd
3 -> 3rd
4 -> 4th
6 -> (...)