Reading and outputting UTF-8 strings in c/cocoa -


In an Objective-C / Coco app, I am using the C function to open a text file, line it Use some lines in the -buy-line and third party function. In psuedo-code:

  char * line = fgets (aFile); Library_function (line); // This function asks for a UTF-8 encoded four * string  

Unless the input file contains special characters (such as Accent or UTF-8 BOM), where But library function, however, if I do this:

  four * line = fgets (aFile); NSString * stringobject = [NSString string withUTF8 string: line]; Library_function ([stringObj UTF8String]);  

Then it all works well and the string gets output correctly.


That [NSString ... What is line I am not? Am I doing something wrong with the line at the beginning? Or is it completely something else?

UTF-8 is a multi-byte character set, which means that some letters There are a number of bytes needed (those you have played). C is of type , so the definition of C of "character" does not match Unicode.

If you want to read Unicode with standard C RTL, you can use

(wchar_t may also be used; I've never researched it.)

Or you can use NSString, which already supports Unicode.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -