Function Character Arrays Class

SortCharacters

Sorts the characters in a string using some specific collating sequence. Result string will contain all of the characters from string vValue, NOT just the unique ones. Usually slower than the SortCharactersBinary function which sorts based on the ASCII value of each character.

Signature (Visual Basic / VBA)

Public Function SortCharacters( _
      ByVal vValue As Variant _
    , Optional ByVal vCompare As Variant _
    ) As Variant

Code Example

    SortCharacters("cbaABCCBA", vbBinaryCompare) = "AABBCCabc"
    SortCharacters("cbaABCCBA", vbTextCompare) = "AAaBBbCCc"
    SortCharacters("cbaABCCBA", dbSortDutch) = "AABBCCabc"

Parameters

Parameter Description
vValue String containing the characters which are to be sorted using a specific sort order/collating sequence. Function returns Null if vValue is Null or cannot be fixed up to a String.
vCompare specifies the sort order/collating sequence by which the characters should be sorted. vCompare defaults to Binary comparisons (sort order based upon ASCII value of characters) if it is missing or Null or cannot be fixed up to a number.

Notes & Version History

Details Note that the dbSort... Constants are defined by Visual Basic or Microsoft Access. You can pass the value of these constants from within other contexts where those constants are not available.
Algotithm This function currently uses a Shell Sort.
Note Characters which have different ASCII values but do match each other within the specified collating sequence are returned in order by their ASCII value.