Sign in to follow this  
Followers 0
SmOke_N

Sort an array by character length.

2 posts in this topic

Has anyone tried an _ArraySortByCharLen()? I thought I had seen a topic on it before, but don't seem to be able to find it at the moment.

I'm going to try it myself, but thought it would be nice if someone had already done something like that before.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites



Has anyone tried an _ArraySortByCharLen()? I thought I had seen a topic on it before, but don't seem to be able to find it at the moment.

I'm going to try it myself, but thought it would be nice if someone had already done something like that before.

this is in scripts and scraps as of this morning,, but just incase someone checks here first, i'll put the code here too.

#cs
    Title:              _ArraySortByLength
    Version:            v1.0
    FileName:           ArraySortByLength.au3
    Description:        Takes a single dimenstion array (with 0 being cound of elements, and returns the array sorted in ascending _
                        or descending order by length of each element
    Author(s)           CameronsDad - Sean - AIM: SiCKPrLck
#ce
Func _ArraySortByLength($InArray,$ascending = 1)
    Dim $TempArray[$InArray[0]+1][2]
    $TempArray[0][0] = $InArray[0]
    For $x = 1 to $InArray[0]
        $TempArray[$x][0] = $InArray[$x]
        $TempArray[$x][1] = Number(StringLen($InArray[$x]))
    Next
    Dim $in,$out
For $out = 1 to $TempArray[0][0] 
    $temp = $TempArray[$out][0]
    $temp2 = Number($TempArray[$out][1])
    $in = $out
    While $in > 1 And Number($TempArray[$in-1][1]) >= $temp2
        $TempArray[$in][0] = $TempArray[$in -1][0]
        $TempArray[$in][1] = $TempArray[$in -1][1]
        $in = $in -1
    WEnd
    $TempArray[$in][0] = $temp
    $TempArray[$in][1] = $temp2
Next
For $y = 1 to $TempArray[0][0]
$InArray[$y] = $TempArray[$y][0]
Next
If Not $ascending Then _ArrayReverse($InArray,1)
Return($InArray)
EndFunc

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0