可以通过VBScript中的自定义方法对对象的ArrayList进行排序吗? [英] Can an ArrayList of objects be sorted by a custom method in VBScript?

查看:89
本文介绍了可以通过VBScript中的自定义方法对对象的ArrayList进行排序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先-我使用的语言是Windows脚本宿主使用的VBScript.我真的没有选择改变它并使用其他东西的选择.

First off - the language I'm using is VBScript, used with Windows Scripting Host. I don't really have the option of changing that and using something else.

这时,我有许多具有多个字段的记录,这些记录是从文件中读取的.我想以多种顺序将它们打印出来(首先,按字母顺序;其次,按位置分组,然后在位置内按字母顺序排序;等等).记录存储在ArrayList中.

At this point, I have a number of records with multiple fields, read in from a file. I want to print them out in a number of orderings (first, in alphabetical order; second, grouped by location and then sorted alphabetically within locations; etc.). The records are stored in an ArrayList.

如果我使用的是Visual Basic而不是VBScript,我知道我可以创建实现iComparer接口的类,然后在要按该顺序排序时使用适当类的对象调用ArrayList的Sort函数. (将字母"对象用于第一类,将"LocationThenAlphabetical"对象用于第二类,等等)

If I was using Visual Basic rather than VBScript, I know that I could create classes which implemented the iComparer interface, and then call the Sort function of the ArrayList with an object of the appropriate class when I wanted to sort in that order (use the Alphabetical object for the first sort, the LocationThenAlphabetical object for the second sort, etc.)

但是,我一直在疯狂地试图找到一种方法来执行此操作或VBScript(我实际上可以使用的语言)中的任何类似方法.我用Google搜索了"VBScript","ArrayList","sort","custom sort","comparison","custom comparison","implements","interface"的无穷组合-但是只要我发现与VBScript相关的结果,它们与如何进行自定义排序无关,并且只要我找到与自定义排序相关的结果,它们就不适用​​于VBScript,即使我在搜索中明确指定了此内容也是如此.

However, I have been going crazy trying to find a way to do that or anything similar in VBScript, the language I actually have available to work with. I've Googled endless combinations of "VBScript", "ArrayList", "sort", "custom sort", "comparison", "custom comparison", "implements", "interface" - but whenever I find results relevant for VBScript, they aren't about how to do a custom sort, and whenever I find results relevant to custom sorting, they aren't applicable to VBScript, even if that was clearly specified in my search.

如果可能的话,我宁愿以正确的方式做到这一点.如果根本无法在VBScript中进行自定义排序,我可以看到一个可能的解决方法,但是它将比我认为的自定义排序增加很多复杂性并使用更多内存.

I would rather do this the right way, if that's possible. If it's simply not possible to do a custom sort in VBScript, I can see a possible work-around, but it would add a lot of complexity and use a lot more memory than I think a custom sort would do.

推荐答案

鉴于您必须将System.Collections.IComparer传递给.Sort方法,并且不能在VBScript中创建.NET对象,因此,答案是否定的.

Given that you'd have to pass a System.Collections.IComparer to the .Sort method and that you can't create .NET objects in VBScript, the answer is no.

这篇关于可以通过VBScript中的自定义方法对对象的ArrayList进行排序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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