macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

compare:options:

INDEX>Foundation>NSString>

オプション付きで文字列を比較して結果を返します
-(NSComparisonResult)compare:(NSString *)aString
             options:(unsigned)mask

解説

オプション付きで文字列を比較して結果を返します。
【比較オプション】
● NSCaseInsensitiveSearch 大文字小文字関係なく比較する
● NSLiteralSearch 大文字小文字を区別して比較する

返り値

( NSComparisonResult )

比較結果

引数

( NSString * )aString

文字列

( unsigned )mask

比較オプション

クラス

NSString

Instance Methods

使用可能

10.0

参照

- caseInsensitiveCompare:
- isEqualToString:

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
NSString *str1 = [NSString stringWithString:@"Abc"];
NSString *str2 = [NSString stringWithString:@"aBC"];
NSString *str3 = [NSString stringWithString:@"Abc"];
if ([str1 compare:str2 options:NSCaseInsensitiveSearch] == NSOrderedSame){
            NSLog(@"YES");
        }else{
            NSLog(@"NO");
        }


if ([str1 compare:str3 options:NSCaseInsensitiveSearch] == NSOrderedSame){
            NSLog(@"YES");
        }else{
            NSLog(@"NO");
        }
}

@end