Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

RossOliver

macrumors regular
Original poster
Nov 6, 2006
157
0
Hey,

I have an SQLite database with a column that may contain words such as café. At the minute I get the text from the database into an NSString using:

Code:
NSString *text = [NSString stringWithUTF8String:( char * )sqlite3_column_text( statement, 0 )];

If I then go on to use the NSString, it appears as "cafe?" instead of "café". I don't understand character encodings - is it as simple as using a different method for the NSString, such as stringWithCString:encoding:? What kind of encoding do I need?

Thanks your time,

-Ross
 

ghayenga

macrumors regular
Jun 18, 2008
190
0
Hey,

I have an SQLite database with a column that may contain words such as café. At the minute I get the text from the database into an NSString using:

Code:
NSString *text = [NSString stringWithUTF8String:( char * )sqlite3_column_text( statement, 0 )];

If I then go on to use the NSString, it appears as "cafe?" instead of "café". I don't understand character encodings - is it as simple as using a different method for the NSString, such as stringWithCString:encoding:? What kind of encoding do I need?

Thanks your time,

-Ross

It depends on what encoding you stuck it into the database with. If you got it from a textfield on your Mac then it's probably MacRoman. Unless you've set the default encoding for your computer to something else. If you put it in with some other utility it might be UTF8. If it came from a Windows machine it could be ISO-Latin1.
 

RossOliver

macrumors regular
Original poster
Nov 6, 2006
157
0
It depends on what encoding you stuck it into the database with. If you got it from a textfield on your Mac then it's probably MacRoman. Unless you've set the default encoding for your computer to something else. If you put it in with some other utility it might be UTF8. If it came from a Windows machine it could be ISO-Latin1.

I created the database in a plain .txt file and used the pre-installed sqlite command utility in Leopard to .import the text file into the database... is there a default format sqlite would use? or would it be defined from the .txt file?

-Ross
 

ghayenga

macrumors regular
Jun 18, 2008
190
0
I created the database in a plain .txt file and used the pre-installed sqlite command utility in Leopard to .import the text file into the database... is there a default format sqlite would use? or would it be defined from the .txt file?

-Ross

It would be set, but not defined, by whatever you created the text file with. Odds are unless you've changed your computers default encoding, or used some program to create the text file that does things quite differently then it's MacRoman. If you used XCode to create the text file XCode writes UTF8 text files by default.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.