gpt4 book ai didi

ios - 多语言 NSString 的奇怪错误。可能是编码问题

转载 作者:行者123 更新时间:2023-11-29 11:05:10 25 4
gpt4 key购买 nike

我认为 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 表示两个字符串不相等。

  1. 我想知道为什么会这样。
  2. 我应该考虑内部 NSString 编码吗?
  3. 如果需要,我该如何转换或处理内部编码?

最佳答案

iOS 文件系统名称在 normalization form D 中,而您的字符串文字是规范化形式 C。

先归一化成C可以得到相同的长度:

NSLog(@"localPath Length:%d",[[localPath precomposedStringWithCanonicalMapping] length]);

关于ios - 多语言 NSString 的奇怪错误。可能是编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14007753/

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