Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alphabetical sort of characters within a string.
#11
(04-25-2024, 01:07 AM)Pete Wrote: A simply way to get the letters in a word or phrase sorted in alphabetical order...

Code: (Select All)
a$ = "uncopyrightable"
For i = 1 To 26
    If InStr(LCase$(a$), Chr$(96 + i)) Then Print Chr$(96 + i);
Next


If you'd like to see how many times a letter occurred, it's just a little more code...

Code: (Select All)
a$ = "lots of letters repeated"
For i% = 1 To 26
    seed% = InStr(LCase$(a$), Chr$(96 + i%))
    If seed% Then
        Do
            If InStr(seed%, LCase$(a$), Chr$(96 + i%)) Then
                Print Chr$(96 + i%);
                seed% = InStr(seed%, LCase$(a$), Chr$(96 + i%)) + 1
            Else
                Exit Do
            End If
        Loop
    End If
Next

Pete

+1 that's pretty cool pete, here is quicker
Code: (Select All)
a$ = "lots of letters repeated"
For i% = 1 To 26
    seed% = InStr(LCase$(a$), Chr$(96 + i%))
    While seed%
        Print Chr$(96 + i%);
        seed% = InStr(seed% + 1, LCase$(a$), Chr$(96 + i%))
    Wend
Next
b = b + ...
Reply


Messages In This Thread
RE: Alphabetical sort of characters within a string. - by bplus - 04-25-2024, 01:28 AM



Users browsing this thread: 2 Guest(s)