Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I? : Alphabeticise a string 3

Status
Not open for further replies.

thefarg

Programmer
Jan 25, 2012
94
NZ
thread707-834151

The above thread has a great bit of code, only it puts the string into reverse alphabetical order. Anyone know how to modify the code to produce normal alphabetical order?
Any help much appreciated,

Mike
 
And just for fun here's how you might do it using the .NET framework ...
Code:
[blue]Public Function SortString(x As String, Optional bASC As Boolean = True) As String
    Dim oAList As Object
    Dim thing As Variant
    Dim source() As Byte
    
    source = StrConv(x, vbFromUnicode)
    
    Set oAList = CreateObject("System.Collections.ArrayList")
    
    For Each thing In source
        oAList.Add thing
    Next
    
    oAList.Sort ' Ok, sort it
    If bASC Then oAList.Reverse ' reverse it if necessary
    
    For Each thing In oAList
        SortString = SortString & Chr$(thing)
    Next

End Function[/blue]
 
PHV: how about:
If bASC Xor d > c Then
x = Left(x, i - 1) & d & Mid(x, i + 1, j - i - 1) & c & Mid(x, j + 1)
i = 0: Exit For
End If

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top