问题描述
我是新的adnroid和我的工作在sqlite的查询,但问题是,当我在字符串中使用的口音。例如:
I'm new in adnroid and I'm working on a query in sqlite, but the problem is when I use accent in my string. Ex:
- AAA
- AAA
- AAA
- AAA
- AAA
- AAA
如果我做的:
SELECT * FROM TB_MOVIE WHERE MOVIE_NAME LIKE '%a%' ORDER BY MOVIE_NAME;
这是回报:
- AAA
- 在AAA(它忽略了其他)
但是,如果我做的:
SELECT * FROM TB_MOVIE WHERE MOVIE_NAME LIKE '%à%' ORDER BY MOVIE_NAME;
这是回报:
- 在AAA(忽略了标题为AAA)
我要选择一个SQLite数据库字符串,而不关心的口音和的情况。请大家帮帮忙。
I want to select strings in a SQLite DB without caring for the accents and the case. Please help.
推荐答案
一般情况下,在SQL字符串比较被列或前pression COLLATE
规则控制。在Android中,只有三个排序序列是$p$p-defined: BINARY(默认),局部和UNI code。他们都不是理想的你的使用情况,以及安装新归类函数的C API是可惜不是Java API中暴露出来。
Generally, string comparisons in SQL are controlled by column or expression COLLATE
rules. In Android, only three collation sequences are pre-defined: BINARY (default), LOCALIZED and UNICODE. None of them is ideal for your use case, and the C API for installing new collation functions is unfortunately not exposed in the Java API.
要解决此问题:
- 添加另一列到表,例如
MOVIE_NAME_ASCII
-
商店值此列移除了重音符号。您可以通过自NFD再presents重音符号大致为纯ASCII +组合口音标记你的字符串规范化为统一code范式D(NFD),并删除非ASCII code点删除口音:
- Add another column to your table, for example
MOVIE_NAME_ASCII
Store values into this column with the accent marks removed. You can remove accents by normalizing your strings to Unicode Normal Form D (NFD) and removing non-ASCII code points since NFD represents accented characters roughly as plain ASCII + combining accent markers:
String asciiName = Normalizer.normalize(unicodeName, Normalizer.Form.NFD)
.replaceAll("[^\\p{ASCII}]", "");
请在从原来的单向code柱这个ASCII码归一列,但显示的数据文本搜索。
Do your text searches on this ASCII-normalized column but display data from the original unicode column.
这篇关于如何忽略口音SQLite的查询(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!