我认为NSString在多语言支持方面存在奇怪的错误。
我在iOS SDK 6.0中开发,在模拟器和iPhone上都有同样的问题。
这是我的代码。
NSString* localPath = [documentsPath stringByAppendingPathComponent:filename];
NSLog(@"%@",localPath);
NSLog(@"%@",@"/Users/vicjames/Library/Application Support/iPhone Simulator/6.0/Applications/8186A14C-1482-44AB-AD3A-0A88DC40EC89/Documents/Data/해부학/11월 29일/095. Michael Learns to Rock - 25 Minutes.mp3");
NSLog(@"localPath Length:%d",[localPath length]);
NSLog(@"String Length:%d",[@"/Users/vicjames/Library/Application Support/iPhone Simulator/6.0/Applications/8186A14C-1482-44AB-AD3A-0A88DC40EC89/Documents/Data/해부학/11월 29일/095. Michael Learns to Rock - 25 Minutes.mp3" length]);
NSLog(@"localPath : URL: %@",[[NSURL fileURLWithPath:localPath] absoluteString]);
NSLog(@"String URL: %@",[[NSURL fileURLWithPath:@"/Users/vicjames/Library/Application Support/iPhone Simulator/6.0/Applications/8186A14C-1482-44AB-AD3A-0A88DC40EC89/Documents/Data/해부학/11월 29일/095. Michael Learns to Rock - 25 Minutes.mp3"] absoluteString]);
以下日志是代码的执行结果。
2012-12-23 00:11:57.741 AudioArchive[11702:c07] /Users/vicjames/Library/Application Support/iPhone Simulator/6.0/Applications/8186A14C-1482-44AB-AD3A-0A88DC40EC89/Documents/Data/해부학/11월 29일/095. Michael Learns to Rock - 25 Minutes.mp3
2012-12-23 00:11:57.741 AudioArchive[11702:c07] /Users/vicjames/Library/Application Support/iPhone Simulator/6.0/Applications/8186A14C-1482-44AB-AD3A-0A88DC40EC89/Documents/Data/해부학/11월 29일/095. Michael Learns to Rock - 25 Minutes.mp3
两个字符串看起来相同。
2012-12-23 00:11:57.742 AudioArchive[11702:c07] localPath Length:194
2012-12-23 00:11:57.742 AudioArchive[11702:c07] String Length:186
但是长度不同。
2012-12-23 00:11:57.743 AudioArchive[11702:c07] localPath : URL: file://localhost/Users/vicjames/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/8186A14C-1482-44AB-AD3A-0A88DC40EC89/Documents/Data/%E1%84%92%E1%85%A2%E1%84%87%E1%85%AE%E1%84%92%E1%85%A1%E1%86%A8/11%E1%84%8B%E1%85%AF%E1%86%AF%2029%E1%84%8B%E1%85%B5%E1%86%AF/095.%20Michael%20Learns%20to%20Rock%20-%2025%20Minutes.mp3
2012-12-23 00:11:57.743 AudioArchive[11702:c07] String URL: file://localhost/Users/vicjames/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/8186A14C-1482-44AB-AD3A-0A88DC40EC89/Documents/Data/%ED%95%B4%EB%B6%80%ED%95%99/11%EC%9B%94%2029%EC%9D%BC/095.%20Michael%20Learns%20to%20Rock%20-%2025%20Minutes.mp3
网址编码显示了差异。
2012-12-23 00:11:57.745 AudioArchive[11702:c07] is Not Equal
NSString也说两个字符串不相等。
答案 0 :(得分:2)
iOS文件系统名称位于normalization form D,而您的字符串文字是标准化形式C.
您可以通过将其标准化为C来获得相同的长度:
NSLog(@"localPath Length:%d",[[localPath precomposedStringWithCanonicalMapping] length]);