获取 localizedStandardCompare 进行比较时使用的字符串

发布于 11-17 01:13 字数 363 浏览 2 评论 0原文

我使用 localizedStandardCompare: 对数组进行排序,它为我提供了以正确的本地化顺序排序的对象。现在我想在 UITableView 的 index 中使用它们,这意味着我需要生成部分标题。由于 localizedStandardCompare: 对它们进行了本地化,因此以“Æ”开头的字符串会与 A 对象一起排序。

因此,如果我迭代数组并为每个第一个字母创建一个部分,我将得到“A”、“Æ”、“A”、“B”等部分。有没有办法获取用于的字符串比较,或者至少模仿它?我尝试过使用不同的编码进行转换,但没有一个会返回“A”表示“Æ”。

关于如何生成本地化字符串的部分标题还有其他建议吗?

I'm sorting an array by using localizedStandardCompare:, which gives me the objects sorted in the correct, localized order. Now I want to use them in the index for a UITableView, which means I need to generate the section titles. Since localizedStandardCompare: localizes them, a string that starts with "Æ" is sorted with the A objects.

So if I iterate the array and make a section for each first letter, I'll get sections "A", "Æ", "A", "B", etc. Is there a way to get the string that was used for comparison, or at least emulate it? I've tried converting with different encodings, but none will return me an "A" for "Æ".

Any other suggestions for how to generate the section titles for localized strings?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏璃陌2024-11-24 01:13:46

您可以使用CFStringTransform方法来获取使用的字符串。

例如,使用 kCFStringTransformToLatin 值从输入字符串中获取简单的拉丁字符串。

这实际上与 localizedStandardCompare: 方法的行为并不完全相同,但您可以使用字符串转换为用于实际排序的对象生成附加属性。

关于这个主题有很多好的资源:

You can use the CFStringTransform method to get the used string.

For example use the kCFStringTransformToLatin value to get a simple latin string from the input string.

This won't actually behave exactly as the localizedStandardCompare: method, but you can use the string transform to generate an additional attribute for the object which you use for the actual sorting.

There are many good resources about this topic:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文