![](/img/trans.png)
[英]how to remove error “[NSString stringWithUTF8String:]: NULL cString' ”?
[英]How to convert nsstring to cString?
我有一個nsstring(filePath),它有音頻文件的路徑。 我想打開音頻文件,所以我想將nsstring轉換為Cstring。
fopen([filePath cStringUsingEncoding:1], "r");
是上面的行是否正確,因為我也可以使用fopen([filePath cString], "r");
。 在某些網站中,提到使用UTF8stringEncoding。 哪個是字符串轉換的正確NSString?
使用UTF8String
:
fopen([filePath UTF8String], "r");
不要使用UTF8String
,而是使用fileSystemRepresentation
。
您應該這樣做,因為HFS +或其他文件系統與Unicode系統不嚴格兼容。 另一個原因:此方法通過將抽象路徑和擴展分隔符(分別為'/'和'。')替換為當前文件系統的等效字符來進行操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.