Array.Sort错误?已知问题或我做错了什么? [英] Array.Sort bug? Known problem or am I doing something wrong?

查看:67
本文介绍了Array.Sort错误?已知问题或我做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用"Array.Sort"对名称列表进行排序并且有效...但有一个小例外:


" Bob Smith"在"Bob"之前出现在结果中。那不应该。如果我改变"鲍勃"到"鲍勃",它有效,但我不想这样做。


我的代码:

 Dim strSortBuffer(99)As String'最多99个条目。
'赋值strSortBuffer(#)
[...]
Array.Sort(strSortBuffer,0,intItemCount + 1)
'设置开始&要排序的数组结束,所以空数组
'条目不包含在排序中。




...其中" strSortBuffer( )"是一系列名字。



我做错了什么?有没有一个简单的修复(我不打算插入我自己的排序例程只是为了解决这个问题。)我只需要知道这是一个已知的bug还是我做错了什么(以及如何解决。) />


TIA

解决方案


我使用" Array.Sort"对名称列表进行排序并且有效...但有一个小例外:


" Bob Smith"在"Bob"之前出现在结果中。那不应该。如果我改变"鲍勃"到"鲍勃",它有效,但我不想这样做。


我的代码:

 Array.Sort(strSortBuffer,0,intItemCount + 1)
'设置开始&要排序的数组结束,所以空数组
'条目不包含在排序中。




...其中" strSortBuffer( )"是一系列名字。



我做错了什么?有没有一个简单的修复(我不打算插入我自己的排序例程只是为了解决这个问题。)我只需要知道这是一个已知的bug还是我做错了什么(以及如何解决。) />


TIA


您好

'这在鲍勃·史密斯之前获得鲍勃  Dim strSortBuffer()As String = {" Freddy"," Bob Smith"," Fred","Mary"," ; Bob"," Andrew"} 
  Array.Sort(strSortBuffer)


I use "Array.Sort" to sort a list of names and it works... but with one minor exception:

"Bob Smith" comes before "Bob" in the result. That shouldn't be. If I change "Bob" to "Bob ", it works, but I don't want to do that.

My code:

Dim strSortBuffer(99) As String ' Upto 99 entries.
' assign strSortBuffer(#)
[...]
Array.Sort(strSortBuffer, 0, intItemCount + 1) ' Set start & End of array to be sorted so empty array ' entries aren't included in the sort.


...where "strSortBuffer()" is an array of names.

Am I doing something wrong? Is there a simple fix (I am not about to insert my own sort routine just to fix this.) I just need to know if this is a known bug or if I'm doing something wrong (and how to fix.)

TIA

解决方案

I use "Array.Sort" to sort a list of names and it works... but with one minor exception:

"Bob Smith" comes before "Bob" in the result. That shouldn't be. If I change "Bob" to "Bob ", it works, but I don't want to do that.

My code:

Array.Sort(strSortBuffer, 0, intItemCount + 1)
' Set start & End of array to be sorted so empty array
' entries aren't included in the sort.


...where "strSortBuffer()" is an array of names.

Am I doing something wrong? Is there a simple fix (I am not about to insert my own sort routine just to fix this.) I just need to know if this is a known bug or if I'm doing something wrong (and how to fix.)

TIA

Hi

' this gets Bob before Bob Smith
 Dim strSortBuffer() As String = {"Freddy", "Bob Smith", "Fred", "Mary", "Bob", "Andrew"}
 Array.Sort(strSortBuffer)


这篇关于Array.Sort错误?已知问题或我做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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