Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I sort arrays using 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

my array is defined as

Dim lines(10000) 

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

like image 498
Oskar Avatar asked Nov 06 '08 13:11

Oskar


People also ask

How do you sort an array of arrays?

To sort the array of arrays, you need to specify based on which element you want to sort them. Here we compare the arrays by their second elements. Then the sort() function loops through the array of arrays and sorts it based on the magnitude of the second elements.

Which method is used to sort an array in Visual Basic?

You can sort the arrays in ascending order as well as descending . We can use Array. Sort method for sorts the elements in a one-dimensional array.

Is in array VBScript?

The IsArray function returns a Boolean value that indicates whether a specified variable is an array. If the variable is an array, it returns True, otherwise, it returns False.

What is sort in VB?

A sorting operation orders the elements of a sequence based on one or more attributes. The first sort criterion performs a primary sort on the elements. By specifying a second sort criterion, you can sort the elements within each primary sort group.


1 Answers

From microsoft

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.

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 
like image 157
Oskar Avatar answered Nov 02 '22 06:11

Oskar