sorting - How to sort an array ("10a", "23a", "1a", "2a") using VBScript -
how sort below array
dim testarray = new array("10a", "23a", "2c", "2a")
using vbscript give output "2a", "2c","10a", "23a"
.
you can use arraylist
instead of array:
testarrray = array("10a", "23a", "2c", "2a") set testlist = createobject("system.collections.arraylist") i=0 ubound(testarray) testlist.add testarray(i) next each e in testlist wscript.echo e next testarray.sort each e in testlist wscript.echo e next
otherwise you'll have implement sorting algorithm yourself. vbscript doesn't have functionality built it.
for simple cases example bubblesort easiest implement:
function bubblesort(byval arr) = 0 ubound(arr) j = + 1 ubound(arr) if arr(i) > arr(j) tmp = arr(i) arr(i) = arr(j) arr(j) = tmp end if next next bubblesort = arr end function
Comments
Post a Comment