Table of Contents

caseInsensitiveCompare

    -(NSComparisonResult)caseInsensitiveCompare:(NSString *)string;  

Returns the result of invoking compare:options: with NSCaseInsensitiveSearch as the only option.

ObjC Sourcecode Example

    NSString *myString1=@"HELLO WORLD";
    NSString *myString2=@"hello world";
 
    if([myString1 caseInsensitiveCompare:myString2]==NSOrderedSame){
 
            NSLog(@"similar");  
        }
    else{
 
            NSLog(@"dissimilar");          
        }
 
      /* 
       defintion NSComparisonResult: 
       enum _NSComparisonResult {NSOrderedAscending = -1, NSOrderedSame, NSOrderedDescending};
       typedef NSInteger NSComparisonResult; 
 
       therefore, the comparative work with numerical values
       */
 
        if([myString1 caseInsensitiveCompare:myString2]==0){
 
            NSLog(@"similar");
        }
        else{
 
            NSLog(@"dissimilar");    
        }
 

Output for this example code

2012-04-15 13:15:33.835 FoundationNSString[795:403] similar
2012-04-15 13:15:33.839 FoundationNSString[795:403] similar