2011-05-11 2 views
1

나는 두 개의 문자열NSStringCompareOptions with NSDiacriticInsensitiveSearch;

  • 문자열 1이 파일에서입니다 비교하려합니다.
  • 문자열 2 내가 두 문자열을 비교하려면

NSArray (미리 정의 된 목록)에 그것이 일치 있다면, 어쩌면 NSLog

NSStringCompareOptions compareOptions = NSDiacriticInsensitiveSearch; 
NSArray* countryIndex = [[NSArray alloc] initWithObjects:@"alpha", 
                 @"beta", 
                 @"gamma", 
                 nil]; 

for (NSString* element in countryIndex) { 
    NSComparisonResult result = [(NSString *)country compare:element options:compareOptions]; 
} 

그래서 내가 무엇을 매우 혼란 스러워요 할 결과는? (번호, 클래스 등)

답변

2

Apple 설명서 (here)를 확인하십시오. . 당신이 'NSComparisonResult'당신이 정수를 포함한,이 열거 형의 볼이 비교 작업 결과 내용을 확인하는 데 사용할 수에 대한 검색을 할 경우

여기에 링크 된 문서에서 짧은 단편이다 :

NSComparisonResult 
These constants are used to indicate how items in a request are ordered. 

enum { 
    NSOrderedAscending = -1, 
    NSOrderedSame, 
    NSOrderedDescending 
}; 
typedef NSInteger NSComparisonResult; 

그래서 예를 들어, 다음 할 수있는 코드에서 사용하기 위해 :

NSStringCompareOptions compareOptions = NSDiacriticInsensitiveSearch; 
NSArray* countryIndex = [[NSArray alloc] initWithObjects:@"alpha", @"beta", @"gamma' nil]; 

for (NSString* element in countryIndex) { 
    NSInteger result = [(NSString *)country compare:element options:compareOptions]; 
    if(NSOrderedAscending == result) { 
     // Do something here... 
    } 
    else if (NSOrderedSame == result) { 
     // Do another thing here if they match... 
    } 
    else { 
     // Try something else... 
    } 
} 
+0

감사합니다. NSOrderedAscending은 무엇을 의미합니까 ?? –

+0

NSString의 [here] (http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#)와 비교하여 Apple의 설명서를 읽는 것이 좋습니다. // apple_ref/doc/uid/20000154-compare_options_). –