Sort alpha numeric array or list of strings which starts with a 3 digit number

Hi Community,
I have an array which contains below elements in string format. I want to sort it based on the first 3 characters which are numbers. I tried Invoke method activity and Linq query but using them it’s sorting based on alphabet not number.
Input can be either array or a list as I am splitting it from a string using delimitter “;”.
Input: {002-UiPath;000-Bot;001-Automation}
Output (Using Sort, Invoke Method Activity (Sort), Linq) : {001-Automation;000-Bot;002-UiPath}

Required Output: {000-Bot;001-Automation;002-UiPath}

If I have 300 such strings then String starting with 000 should come first and 300 should come last.


YourArrayOrList.OrderBy(Function (x) CInt(Regex.Match(x,"^\d+").Value)).toArray


Hi @kspsarma

Give a try to this
{“002-UiPath”,“000-Bot”,“001-Automation”}.OrderBy(Function(x) System.Text.RegularExpressions.Regex.Match(x,“[0-9]{3}”).Value).ToArray()

Hi @kspsarma,
You can use the below expression to get the array elements in ascending order with respect to the numbers.

ArrayVariable.OrderBy(function(x) Cint(x.ToString.Split("-"c).First)).ToArray


1 Like


Another way

ArrayList.OrderBy(function(x) Cint(x.SubString(0,3))).ToArray