Objective-C: format numbers to ordinals: 1, 2, 3, .. to 1st, 2nd, 3rd

后端 未结 5 1642
悲哀的现实
悲哀的现实 2021-01-04 00:57

In Objective C, is there any way to format an integer to ordinals 1 => \"1st\", 2 => \"2nd\" etc... that works for any language? So if the user

5条回答
  •  [愿得一人]
    2021-01-04 01:39

    You could use ICU, which includes a way of doing what you describe:

    http://icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html

    You don't say what context you're using Objective-C in, but if you're writing for Cocoa, ICU is actually present. However, reaching down to talk to it directly can be a bit tricky.

    [edited to link to someone who actually seems to have figured out how to build ICU and link it]

    How to build ICU so I can use it in an iPhone app?

提交回复
热议问题