Forum Discussion

kbhaskar's avatar
kbhaskar
Occasional Contributor
7 years ago

how to sort list of strings which are there in array list? any help is appreciable

hi all,

 

can anyone explain solution for my problem

 

issue:

there is webtable i need to verify particular column values are in sorted format means any function or method for sorting strings in the arraylist.

 

please reply asap,

 

thank you 

bhaskar

  • '####################################################################################################
    '# Function Name : fn_ValidateArrayOrder
    '# Description : This method will verfy an array is ascending or descending order
    '# Input parameters : arrInput,strOrderType
    '# arrInput : Array as input
    '# strOrderType : ASCENDING or DESCENDING
    '# Return Value : True or False
    '####################################################################################################
    Function fn_ValidateArrayOrder(arrInput,strOrderType)
    On Error resume Next
    Dim BlnFlag
    BlnFlag = False
    Select Case UCase(strOrdertype)
    Case "ASCENDING"
    For i = 0 to UBound(arrInput)-1
    If StrComp(arrInput(i), arrInput(i+1), 1)=-1 Then
    BlnFlag = True
    End If
    Next
    Case "DESCENDING"
    For i = 0 to UBound(arrInput)-1
    If StrComp(arrInput(i), arrInput(i+1), 1)=1 Then
    BlnFlag = True
    End If
    Next
    End Select
    fn_ValidateArrayOrder=BlnFlag
    End Function

     

    Please try to use this code ,it may be help you.

  • baxatob's avatar
    baxatob
    Community Hero

    Hi,

     

    Using Python as a scripting language, you can make a simple check:

     

     

    def is_sorted(arr):
      if arr == sorted(arr):
        return True
      else:
        return False


    arr = ['d', 'c', 'a', 'e', 'b']
    is_sorted(arr)
    >> False

    arr = ['a', 'b', 'c', 'd', 'e']
    is_sorted(arr)
    >> True

     

    • sanj's avatar
      sanj
      Super Contributor

      Instead of checking to see if its sorted why dont you just sort it and you are done

      A sorted function can be used to sort an array list