使用数字正确排序名称

编程入门 行业动态 更新时间:2024-10-26 20:25:51
本文介绍了使用数字正确排序名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

更多推荐

使用数字正确排序名称

本文发布于:2023-11-09 15:15:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572704.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确   名称   数字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!