1
我認爲NSString有多語言支持怪異的錯誤。多語言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
URL編碼顯示差異。
2012-12-23 00:11:57.745 AudioArchive[11702:c07] is Not Equal
另外NSString說兩個字符串不相等。
- 我想知道爲什麼會發生這種情況。
- 我應該考慮內部NSString編碼嗎?
- 如果我應該如何轉換或處理內部編碼?
謝謝!正如你回答的那樣,這段代碼解決了所有的問題〜 「localPath = [localPath precomposedStringWithCanonicalMapping];」 –