Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alphabetical sort of characters within a string.
#38
(04-26-2024, 07:23 AM)euklides Wrote: Pete wrote:

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


Ok, very short.
But, if the word has the same letter twice (or more), some of them are lost if the final result must have the same length.
Disregarding the lost letters mentioned above, what if we adjust the for/next values so we can eliminate two additions that repeat every loop? Would that speed things up a little, or are the calculation results cached somehow so that recalcs are not needed?

a$ = "uncopyrightable"
For i = 97 To 122
    If InStr(LCase$(a$), Chr$(i)) Then Print Chr$(i);
Next
Reply


Messages In This Thread
RE: Alphabetical sort of characters within a string. - by Circlotron - 04-26-2024, 01:08 PM



Users browsing this thread: 2 Guest(s)