Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alphabetical sort of characters within a string.
#10
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
Shoot first and shoot people who ask questions, later.
Reply


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



Users browsing this thread: 2 Guest(s)