排序-大写字母比小写字母优先 [英] Sorting -- Capital letters come first than small letters
问题描述
大家好,
我正在尝试对包含文本的网格控制列进行排序.我有一个问题.当我按升序对所有内容进行排序时,将"AA"放在"aa"之前,将大写字母放在首位,然后将小写字母放在首位,如何将其反转?每个人都看到相同的问题还是有人解决了?它.
我希望升序排序结果为::
aa
bb
AA
Ab
etc
Hello Everyone,
I am trying to sort my grid control column which contains text. I have one issue. When i am sorting everything in ascending order it puts "AA" before "aa", it is putting the Capital letters first and then the small letters, how to reverse this? does everyone see the same problem or has anyone solved. it.
I want the ascending sort result to be of type ::
aa
bb
AA
Ab
etc
推荐答案
这是由于ASCII字符集中的字符顺序(请参见 ^ ]));如果要在程序中进行任何形式的数据处理,这是您应该真正理解的东西.我不确定网格控件是否具有允许您修改排序顺序的属性,否则,您将不得不编写自己的排序子例程.
This is due to the order of the characters in the ASCII character set (see here[^]); this is something you should really understand if you are going to do any form of data manipulation in your programs. I am not sure if the grid control has any properties that allow you to modify the sort order, if not you will have to write your own sort subroutine.
您通常应使用本地化排序向用户显示数据时.
通常情况下,大写字母并不重要,除非字符串的大小写不同.
我认为在大多数语言中,大写字母排在首位.
因此,通常排序的输出应为:
You should typically uses a localized sort when displaying data to the user.
Normally in a sort, capitalization don''t matters except when a string only differ in capitalisation.
I would think that in most language capital letter come first.
Thus, the typically sorted output should be:
AA
aa
Ab
bb
C ++为此提供了语言环境...但是我从未使用过它们.我通常在使用Windows排序功能
lstrcmp函数(Win32 API) [
C++ has locale for that... but I never used them. I was generally using Windows sort functions
lstrcmp Function (Win32 API)[^]
When the sorting is used for display purpose, sort should typically be done according to text language (or OS language). When sort is only used internally, default sort might be appropriate.
预期的输出肯定需要自定义排序例程.
您可以将std::sort
函数与用户定义的谓词函数一起使用,该函数将所有小写字母置于大写字母之前.
Richard 发布的ASCII表是必须知道的.
The expected output definitely calls for a custom sorting routine.
You could use thestd::sort
function with a user defined predicate function that puts all lower case before upper case.
The ASCII table posted by Richard is a must know.
这篇关于排序-大写字母比小写字母优先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!