Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道如何在两个字符串之间计算第一个字母,例如 string1 以字母“a”开头,而 string2 以字母“b”开头,那么 string1 必须首先显示。
不要重新发明轮子。采用
NSComparisonResult order = [firstString compare:secondString];
反而。(NSComparisonResult 文档)
这并不严格符合 UNICODE 字符串比较规则,这对于非拉丁字母来说很复杂,但至少很快:
NSString *first = [string1 characterAtIndex:0] <= [string2 characterAtIndex:0] ? string1 : string2;