苹果手机 。 stringWithCString编码

时间:2011-10-05 18:36:50

标签: iphone

我正在使用以下内容编译代码段:

char* filename = (char*) malloc( fileInfo.size_filename +1 );
unzGetCurrentFileInfo(_unzFile, &fileInfo, filename, fileInfo.size_filename + 1, NULL, 0, NULL, 0);
filename[fileInfo.size_filename] = '\0';

NSString * strPath = [NSString  stringWithCString:filename];

但不推荐使用stringWithCString。我应该将其改为

NSString * strPath = [NSString  stringWithCString:filename encoding:????];

此名称所示的文件名表示文件系统,文件和目录上的条目。我如何知道编码文件名正在使用?我的意思是,我可以放UTF-8,但谁知道世界各地的哪些编码用户会使用。如果我选择任何编码,我将限制它。

如何解决这个问题,为每个用户设置正确的编码。

感谢

1 个答案:

答案 0 :(得分:4)

实际上,对于C路径,你想要的东西有点丑陋:

NSString *strPath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:filename length:strlen(filename)];

走另一条路:

const char *cPath = [nsFilename fileSystemRepresentation];
相关问题