NSStringCompareOptions 与 NSDiacriticInsensitiveSearch;
我正在尝试比较两个字符串
- String1 来自文件。
- String2 在
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];
}
所以我很困惑结果是什么? (数量、类别等)
I am trying to compare two strings
- String1 is from a file.
- String2 is in an
NSArray
(predefined list)
I want to compare the two strings and if it's a match, maybe do an 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];
}
So I'm very confused at what result is? (number, class, etc)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请在 此处查看 Apple 文档。
如果您搜索“NSComparisonResult”,您将看到它是一个枚举,其中包含可用于检查比较操作结果的常量。
以下是链接文档中的一个简短片段:
例如,为了在您的代码你可以执行以下操作:
Check the Apple documentation available here.
If you do a search for 'NSComparisonResult' you will see it's an enum, containing constants you can use to check what the comparison operation resulted in.
Here's a brief snippet from the linked document:
So for instance, in order to use it in your code you could do the following: