[英]How to convert nsstring to cString?
I have a nsstring(filePath), which has the path to the audio file. 我有一个nsstring(filePath),它有音频文件的路径。 I want open the audio file, so I want to convert the nsstring to Cstring.
我想打开音频文件,所以我想将nsstring转换为Cstring。
fopen([filePath cStringUsingEncoding:1], "r");
is the above line is correct or not, because I can also use fopen([filePath cString], "r");
是上面的行是否正确,因为我也可以使用
fopen([filePath cString], "r");
. 。 In some websites it is mentioned to use UTF8stringEncoding.
在某些网站中,提到使用UTF8stringEncoding。 Which is the the right NSString to string conversion?
哪个是字符串转换的正确NSString?
使用UTF8String
:
fopen([filePath UTF8String], "r");
Don't use UTF8String
, but fileSystemRepresentation
. 不要使用
UTF8String
,而是使用fileSystemRepresentation
。
You should do this because HFS+ or other file systems are not strictly compatible with the Unicode system. 您应该这样做,因为HFS +或其他文件系统与Unicode系统不严格兼容。 Another reason: This method operates by replacing the abstract path and extension separator characters ('/' and '.' respectively) with their equivalents for the current file system.
另一个原因:此方法通过将抽象路径和扩展分隔符(分别为'/'和'。')替换为当前文件系统的等效字符来进行操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.