使用数字正确排序名称 [英] Sorting names with numbers correctly
问题描述
对于排序项目名称,我想正确支持数字。即:
1 Hamlet
2 Ophelia
...
10 Laertes
而不是
1 Hamlet
10 Laertes
2 Ophelia
...
有没有人知道已经支持该函数的比较函子?
(即一个可以传递给 std :: sort
)
我基本上有两种模式支持:前导数字(如上)和末尾数字,类似于explorer:
多莉
pre>
多莉(2)
多莉(3)
(我想我可以工作:比较字符,并且处理数字值不同的,但是,这可能会破坏unicode collaiton和whatnot)
解决方案这称为字母数字排序。
签出此链接:字母算法For sorting item names, I want to support numbers correctly. i.e. this:
1 Hamlet 2 Ophelia ... 10 Laertes
instead of
1 Hamlet 10 Laertes 2 Ophelia ...
Does anyone know of a comparison functor that already supports that?
(i.e. a predicate that can be passed tostd::sort
)I basically have two patterns to support: Leading number (as above), and number at end, similar to explorer:
Dolly Dolly (2) Dolly (3)
(I guess I could work that out: compare by character, and treat numeric values differently. However, that would probably break unicode collaiton and whatnot)
解决方案That's called alphanumeric sorting.
Check out this link: The Alphanum Algorithm这篇关于使用数字正确排序名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!