创建可查询的字符串
我想将字符串以更可查询的类似 slug 的格式存储到数据库中,强制其小写,用拉丁字母替换重音字母(ä -> a, ö -> o, ç -> c 等)并用破折号等替换其他特殊字符。这种格式有标准吗?在 Java 中实现它的更好方法是什么?
I'd like to store strings also in a more queryable slug-like format to the database, forcing it to lowercase, replacing the accented letters with their latin counterparts (ä -> a, ö -> o, ç -> c etc.) and replacing other special characters with e.g. dashes. Is there a standard for these kind of format? What would be preferable means to achieve it in Java?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
数据库可以通过排序规则为您完成此操作。排序规则指定特定字符集中的哪些字符在比较时可以被视为彼此等效。
看一下这个排序规则的直观示例:
http://www .collation-charts.org/mysql60/mysql604.utf8_general_ci.european.html
下面是 MySQL 手册中关于排序规则如何工作的详细描述:
http://dev.mysql.com/doc/refman/5.0/en/charset-syntax.html
The database can do this for you through collations. Collations specify which characters in a specific character set can be considered equivalent with each other when compared.
Have a look at this for visual example of a collation:
http://www.collation-charts.org/mysql60/mysql604.utf8_general_ci.european.html
Here's a good description of how collations work from the MySQL manual:
http://dev.mysql.com/doc/refman/5.0/en/charset-syntax.html
这是迄今为止我发现效果最好的解决方案:
此转换:¿Qué? to que, Cool!!!!1 to Cool-1 and åæø to a.
This is the solution that I've found working best so far:
This converts: ¿Qué? to que, Cool!!!!1 to cool-1 and åæø to a.