gpt4 book ai didi

iphone - IOS isEqualToString 不工作

转载 作者:可可西里 更新时间:2023-11-01 06:20:54 27 4
gpt4 key购买 nike

下面的示例程序输出相同,但程序无法正常运行。

NSDirectoryEnumerator *directoryEnumerator = [[NSFileManager defaultManager]
enumeratorAtPath:kDocdir];

for (NSString *pathi in directoryEnumerator)
{
NSString *fileName_Manager = [pathi lastPathComponent];
NSLog(@"fileName_Manager = %@",fileName_Manager);

Artist *name_Databse = [self.fetchedResultsController
objectAtIndexPath:IndexPath];
NSLog(@"name_Databse = %@",name_Databse.name);



if ([fileName_Manager isEqualToString:name_Databse.name]) {
NSLog(@"Same Name");
}else{
NSLog(@"Different Name");
}

}

输出:

2013-04-25 15:37:43.256 Player[36436:907] fileName_Manager = alizée - mèxico - final j'en
2013-04-25 15:37:43.272 Player[36436:907] name_Databse = alizée - mèxico - final j'en
2013-04-25 15:37:44.107 Player[36436:907] Different Name

名称中有特殊字符时无法正常工作。为什么会这样?谢谢...

这里有同样的问题:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == %@",[pathi lastPathComponent]];

如何在此处进行编辑?

最佳答案

isEqualToString: 的文档表明您可能遇到了问题:

The comparison uses the canonical representation of strings, which for a particular string is the length of the string plus the Unicode characters that make up the string. When this method compares two strings, if the individual Unicodes are the same, then the strings are equal, regardless of the backing store. “Literal” when applied to string comparison means that various Unicode decomposition rules are not applied and Unicode characters are individually compared. So, for instance, “Ö” represented as the composed character sequence “O” and umlaut would not compare equal to “Ö” represented as one Unicode character.

尝试使用 (NSOrderedSame == [string1 localizedCompare:string2])

此外,如果您还没有,请查看 Apple 示例代码“International Mountains”,它处理了许多本地化问题。

关于iphone - IOS isEqualToString 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16215439/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com