-1

For my app I want to be able to use unicode caracters like \n, and these ones : http://www.easyapns.com/category/just-for-fun

The text is stored in a sqlite3 database, and when I read it, I get for example the text \ue415 instead of the smiley. I neither have a line break, but a \n .

I'm able to display the smileys and line breaks using this piece of code :

NSString* unicodeString = [myString stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
unicodeString = [unicodeString stringByReplacingOccurrencesOfString:@"\\ue022" withString:@"\ue022"];
// etc...

But I would like to find a generic way to do this, in order to be able to display all the unicode caracters.

I'm getting the text from my sqlite3 database this way :

NSString* title = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 3)];

I tried to replace \\ by \, but it is not possible to write the string @"\", because it escapes the " ... I tried to replace \\\\ by \\, but it doesn't work. I also tried to get the string from the database using other encoding, without success...

Any idea ?

Tim Autin
  • 6,043
  • 5
  • 46
  • 76
  • 2
    You must be doing something else wrong. sqlite can store any UTF-8 string you can put in an `NSString` as-is. There is no need to do any pre or post processing. – rmaddy Aug 19 '13 at 17:04
  • Thanks for your answer, but I don't think that the problem come from sqlite, but more from the UILabel (I made my database the old way using a text file with my scheme and inserts, and the command sqlite3 my_db.sqlite3 < my_db.sql). I read somewhere else that a guy had the same problem when reading a string from a XML file and displaying unicode caracters in a UILabel (he solved his problem whith stringByReplacingOccurrencesOfString). – Tim Autin Aug 19 '13 at 17:18
  • (thanks for the down vote with no explication >< ) – Tim Autin Aug 19 '13 at 17:23
  • That's what I said, the problem is not with sqlite but with the data you put in sqlite. Look into how you get data into the database. IF you need help with code related to that process, update your question. – rmaddy Aug 19 '13 at 17:29
  • As I said, I don't think that the problem came from the way I put the data into the database, but from the way I extracted it. I found a solution, see my answer. Thank you anyway :) – Tim Autin Aug 19 '13 at 17:56

1 Answers1

0

I finally found my solution there (not the accepted answer, the one from Nikolai Ruhe) :

Using Objective C/Cocoa to unescape unicode characters, ie \u1234

NSString* convertedString = [myString mutableCopy];
CFStringRef transform = CFSTR("Any-Hex/Java");
CFStringTransform((__bridge CFMutableStringRef)convertedString, NULL, transform, YES);

It does not escape the \n though, but it can easilly be done with stringByReplacingOccurrencesOfString.

Community
  • 1
  • 1
Tim Autin
  • 6,043
  • 5
  • 46
  • 76