Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert nsstring to cString?

I have a nsstring(filePath), which has the path to the audio file. I want open the audio file, so I want to convert the nsstring to Cstring.

  fopen([filePath cStringUsingEncoding:1], "r");

is the above line is correct or not, because I can also use fopen([filePath cString], "r");. In some websites it is mentioned to use UTF8stringEncoding. Which is the the right NSString to string conversion?

like image 625
Warrior Avatar asked Oct 26 '10 05:10

Warrior


2 Answers

Use UTF8String:

fopen([filePath UTF8String], "r");
like image 183
Jacob Relkin Avatar answered Nov 07 '22 00:11

Jacob Relkin


Don't use UTF8String, but fileSystemRepresentation.

You should do this because HFS+ or other file systems are not strictly compatible with the Unicode system. Another reason: This method operates by replacing the abstract path and extension separator characters (‘/’ and ‘.’ respectively) with their equivalents for the current file system.

like image 27
Antoine Rosset Avatar answered Nov 06 '22 22:11

Antoine Rosset