JAVA 或 JAVA SCRIPT 或 Idoc SCRIPT 按字母顺序排序
我有以下任务:
类别中的所有项目都应按字母顺序排序,示例除外。特殊字符和数字应显示在字母之前。
我面临着一个问题。大多数标准排序函数和插件都使用 ASCII 表。此表中以下符号:~、}、{等的索引多于字母,例如: 排序的实际结果是:
1 - #1 A T
2 - A T
3 - {C T
我需要得到:
1 - #1 A T
2 - {C T
3 - A T
请尽快给我你的建议或任何例子。
此致。
I have the following task:
All items within categories should be sorted alphabetically except for Examples. Special characters and numbers should be displayed before letters.
I'm facing with a problem. Most of standard sort functions and plugins are being used the ASCII table. In this table the following symbols: ~,},{ etc. have the index more than letters,for example:
Actual result of sorting is:
1 - #1 A T
2 - A T
3 - {C T
I need to get:
1 - #1 A T
2 - {C T
3 - A T
Please give me your piece of advice or any examples ASAP.
Best Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“时间不够”的解决方案:将数据切割成 3 个数组或列表:特殊字符、数字、字符。 (测试是否为数字或介于“a”和“Z”之间)。使用 Java 中的 fe Collections.sort 或 Arrays.sort 对它们进行排序,这将对每个集合或数组进行排序,然后将它们附加在一起,但不再进行任何排序。我还没有测试过这个,但看起来它可能有效
"short of time" solution : cut data in 3 arrays or lists : special chars, numbers, chars. (test if is number or is between 'a' and 'Z'). Sort them with f.e. Collections.sort or Arrays.sort in Java which will sort each collection or array and then append them together but don't make any sorting anymore. I haven't tested this, but it looks like it might work
这有点乏味,主要是为了防止“100”排在“2”之前。
您可以将字符串拆分为单个字符和数字组。
对任何数字组(如数字)进行排序,并按字符代码对其他所有内容进行排序,
为任何 az 字符添加一些“权重”后。
This is a little tedious, mostly to keep '100' from sorting before '2'.
You can split the strings into individual characters and groups of digits.
Sort any digit groups like numbers, and sort everything else by character code,
after adding some 'weight' to any a-z character.