使用数字正确排序名称 [英] Sorting names with numbers correctly

查看:131
本文介绍了使用数字正确排序名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于排序项目名称,我想正确支持数字。即:

  1 Hamlet 
2 Ophelia
...
10 Laertes

而不是

  1 Hamlet 
10 Laertes
2 Ophelia
...

有没有人知道已经支持该函数的比较函子?

(即一个可以传递给 std :: sort



我基本上有两种模式支持:前导数字(如上)和末尾数字,类似于explorer:

 多莉
多莉(2)
多莉(3)
pre>

(我想我可以工作:比较字符,并且处理数字值不同的,但是,这可能会破坏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 to std::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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆