I have a database that I extract data from to my Android project. There are some strings of text there with the swedish letters å, ä, ö written as : √•=å, √§=ä, √δ=ö. What would be the best way of converting these symbols to the actual letters before I print them on the textview in the app? Is a substitution, like replace √• with å, the way to go? How would that be entered in the query that is now fetching the data:
public Cursor getAlternative1(long categoryid, int questionid) {
final String MY_QUERY = "SELECT question, image, alternative, questionid, correct FROM tbl_question a INNER JOIN tbl_alternative b ON a._id=b.questionid AND b.categoryid=a.categoryid WHERE a.categoryid=? AND a._id=?";
Cursor cursor = mDb.rawQuery(MY_QUERY, new String[]{String.valueOf(categoryid), String.valueOf(questionid)});
if (cursor != null) {
cursor.moveToFirst();
}
return cursor;
}
Thanks for any help!
It appears that your string data was originally encoded in UTF-8, but are getting misinterpreted as MacRoman.
The first thing to do is make sure your data is being stored in the database correctly. You can use
SELECT HEX(SomeColumn)
to see the raw bytes that are being stored for the string. The default encoding in SQLite is UTF-8, so a correctly-encoded string will haveC3A5
forå
,C3A4
forä
, andC3B6
forö
. If you seeE2889AE280A2
,E2889AC2A7
,E2889AE28882
, then the misinterpretation of the characters (å→√•, ä→√§, ö→√δ) is happening before the data gets into the DB. If you just see8C
,8A
, and9A
, then the reverse misinterpretation is being made.If your database is correct, then it's probably an I/O routine that thinks the system encoding is UTF-8 when it's really MacRoman. Try something like
System.setProperty("file.encoding", "macintosh");
.