本文介绍了如何使用 vbscript 对数组进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在扫描一个文件,寻找与某个正则表达式匹配的行,然后我想打印出匹配但按字母顺序排列的行.我确定这是微不足道的,但 vbscript 不是我的背景

I'm scanning through a file looking for lines that match a certain regex pattern, and then I want to print out the lines that match but in alphabetical order. I'm sure this is trivial but vbscript isn't my background

我的数组定义为

Dim lines(10000)

如果这有什么不同,我正在尝试从普通的 cmd 提示符执行我的脚本

if that makes any difference, and I'm trying to execute my script from a normal cmd prompt

推荐答案

来自 微软

在 VBScript 中对数组进行排序从未如此简单;那是因为 VBScript 没有任何类型的排序命令.反过来,这总是意味着 VBScript 脚本编写者被迫编写自己的排序例程,例如冒泡排序例程、堆排序、快速排序或其他类型的排序算法.

Sorting arrays in VBScript has never been easy; that’s because VBScript doesn’t have a sort command of any kind. In turn, that always meant that VBScript scripters were forced to write their own sort routines, be that a bubble sort routine, a heap sort, a quicksort, or some other type of sorting algorithm.

所以(使用 .Net,因为它安装在我的电脑上):

So (using .Net as it is installed on my pc):

Set outputLines = CreateObject("System.Collections.ArrayList")

'add lines
outputLines.Add output
outputLines.Add output

outputLines.Sort()
For Each outputLine in outputLines
    stdout.WriteLine outputLine
Next

这篇关于如何使用 vbscript 对数组进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 16:46
查看更多