Moderators SmOke_N Posted December 19, 2005 Moderators Posted December 19, 2005 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. 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.
seandisanti Posted December 20, 2005 Posted December 20, 2005 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now