有没有一种方法可以对“维生素 B12”进行排序?前面不是“维生素B6”吗?
在 Ruby on Rails 中,默认排序顺序
Vitamin A
Vitamin B12
Vitamin B6
为 是否有一种机制或快速方法可以按自然语言方式排序,以便 B6
显示在 B12
之前?
In Ruby on Rails, the default sort order will be
Vitamin A
Vitamin B12
Vitamin B6
Is there a mechanism or quick way so that it will sort by a natural language way so that B6
shows before B12
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试类似的操作:
它按数字和非数字交替排序。
这可能类似于 Windows 中对目录中的文件名进行排序时所做的操作。
Update: A newer version. Doesn't need
' '+
, as it is automatically supplied bysplit
. It also removes the redundancy of specifying the complementary\d
and\D
in the regex.Try something like:
It sorts alternatively by digits and by non-digits.
This is probably similar to what is done in Windows when sorting the file names within a directory.
Update: A newer version. Doesn't need
' '+
, as it is automatically supplied bysplit
. It also removes the redundancy of specifying the complementary\d
and\D
in the regex.