compare: options:
Returns the result of invoking
compare:options:range:
with a given mask as the options and the receiver’s full extent as the range.Parameters
- aString
- The string with which to compare the receiver.This value must not be
nil
. If this value isnil
, the behavior is undefined and may change in future versions of OS X. - mask
- Options for the search—you can combine any of the following using a C bitwise OR operator:
NSCaseInsensitiveSearch
,NSLiteralSearch
,NSNumericSearch
. See String Programming Guide for details on these options.
Return Value of [NSString compare options]
The result of invoking
compare:options:range:
with a given mask as the options and the receiver’s full extent as the range.Discussion of [NSString compare options]
If you are comparing strings to present to the end-user, you should typically use
localizedCompare:
orlocalizedCaseInsensitiveCompare:
instead, or use compare:options:range:locale:
and pass the user’s locale.
Example of [NSString compare options]
if([txtAnswer.text compare:answer options:NSCaseInsensitiveSearch] == NSOrderedSame)
{
// Do somehing
}
Example of [NSString compare options]
NSComparisonResult result = [selectedString compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];