Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alphabetical sort of characters within a string.
#59
@bplus @bplus @bplus @bplus

THIS IS HOW IT SHOULD BE DONE!!!

Code: (Select All)
Type AnaType
    word As String
    sorted As String
End Type

dict$ = _ReadFile$("WORDS.txt")
Dim words(25000) As AnaType, tempsort(22) As String
For i = 1 To 22: tempsort(i) = Space$(i): Next

startPos = 1: endPos = 1: count = 1: l = Len(dict$)
t# = Timer(0.001)
While startPos <= l
    count = count + 1
    p = InStr(startPos, dict$, Chr$(13))
    word$ = Mid$(dict$, startPos, p - startPos)

    startPos = p + 2
    ReDim temp(65 To 90)
    l1 = Len(word$)
    For i = 1 To l1
        a = Asc(word$, i)
        temp(a) = temp(a) + 1
    Next
    p = 1
    For i = 65 To 90
        For j = 1 To temp(i)
            Asc(tempsort(l1), p) = i
            p = p + 1
        Next
    Next
    words(count).word = word$
    words(count).sorted = tempsort(l1)
Wend
t1# = Timer(0.001)

Print Using "###.### seconds to generate and sort dictionary and anagram listings"; t1# - t#

For i = 1 To 20
    Print words(i).word, words(i).sorted
Next


   
Reply


Messages In This Thread
RE: Alphabetical sort of characters within a string. - by SMcNeill - 04-28-2024, 02:44 AM



Users browsing this thread: 3 Guest(s)