如何像iTunes排序那样对NSString进行排序? [英] How to sort NSString like iTunes sorting?

查看:110
本文介绍了如何像iTunes排序那样对NSString进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用iTunes排序规则对NSString数组进行排序。此规则忽略了诸如a,an,The之类的主要文章。还有一些其他规则。 Apple发布了一篇关于它的文章。
iTunes 7.3:音乐排序顺序的变化

I want to sort array of NSString using iTunes sorting rules. This rule ignores leading articles such as "a, an, The". There are some other rules. Apple has posted an article about it. iTunes 7.3: Changes in music sort order

任何人都知道iOS 5.0或更高版本中可以解决这个问题的任何API吗?

Anyone know any APIs in iOS 5.0 or later that can solve this?

干杯,
Fedry

Cheers, Fedry

推荐答案

首先,遍历NSString并检查第一个单词是否是您不想使用的单词 hasPrefix:,然后你可以用 stringByReplacingOccurrencesOfString替换它们:withString:

First of all, iterate through the NSString's and check if the first words are words you don't want using hasPrefix:, then you can replace them with stringByReplacingOccurrencesOfString:withString:

然后你可以像这样对字符串进行排序:

Then you can sort the string's like this:

sortedArray = [stringArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

或者您可以创建自己的方法来比较2个字符串而不是使用 localizedCaseInsensitiveCompare:

Or you can just create your own method for comparing between 2 strings instead of using localizedCaseInsensitiveCompare:

这篇关于如何像iTunes排序那样对NSString进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆