如何在 Android 应用程序中显示瑞典语字符?

发布于 2024-10-17 10:29:19 字数 782 浏览 8 评论 0原文

我有一个数据库,我可以从中提取数据到我的 Android 项目中。那里有一些文本字符串,其中瑞典字母 å、ä、ö 写为:√•=å、√§=ä、√δ=ö。在将这些符号打印到应用程序的文本视图上之前,将这些符号转换为实际字母的最佳方法是什么?替换(例如用 å 替换 √•)是正确的方法吗?如何将其输入到现在正在获取数据的查询中:

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;
            }

感谢您的帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北笙凉宸 2024-10-24 10:29:19

看来您的字符串数据最初是用 UTF-8 编码的,但被误解为MacRoman

首先要做的就是确保您的数据正确存储在数据库中。您可以使用 SELECT HEX(SomeColumn) 来查看为字符串存储的原始字节。 SQLite 中的默认编码是 UTF-8,因此正确编码的字符串将有 C3A5 表示 åC3A4 表示 ä< /code> 和 C3B6 表示 ö。如果您看到 E2889AE280A2E2889AC2A7E2889AE28882,则说明字符 (å→√•、ä→√§、ö→√ δ)发生在数据进入数据库之前。如果您只看到 8C8A9A,那么就会产生相反的误解。

如果你的数据库是正确的,那么它可能是一个 I/O 例程认为系统编码是 UTF-8,而实际上它是 MacRoman。尝试类似 System.setProperty("file.encoding", "macintosh");。

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 have C3A5 for å, C3A4 for ä, and C3B6 for ö. If you see E2889AE280A2, E2889AC2A7, E2889AE28882, then the misinterpretation of the characters (å→√•, ä→√§, ö→√δ) is happening before the data gets into the DB. If you just see 8C, 8A, and 9A, 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");.

梦年海沫深 2024-10-24 10:29:19

这是一篇有点旧的文章,但如果您使用 Windows cmd shell 将数据导入到 sqlite 中,请尝试在 shell 中执行此操作:

c:> chcp 65001

这会将 cmd shell 的代码页更改为 utf 8

c:> sqlite3数据库.db < inserts.sql

其中inserts.sql 是UTF-8(没有BOM 字符!!)的插入序列。您可以使用 Notepad++ 创建此类文件

希望它有帮助

This is a little old post, but if you are importing the data into sqlite using windows cmd shell, try doing this in the shell:

c:> chcp 65001

This will change the code page of cmd shell to utf 8

c:> sqlite3 database.db < inserts.sql

where inserts.sql is a UTF-8 (WITHOUT BOM CHARACTER!!) sequence of inserts. You can create that kind of file using Notepad++

Hope it helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文