![]() |
Alphabetical sort of characters within a string. - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Alphabetical sort of characters within a string. (/showthread.php?tid=2620) |
RE: Alphabetical sort of characters within a string. - bplus - 04-25-2024 (04-25-2024, 01:07 AM)Pete Wrote: A simply way to get the letters in a word or phrase sorted in alphabetical order... +1 that's pretty cool pete, here is quicker Code: (Select All) a$ = "lots of letters repeated" RE: Alphabetical sort of characters within a string. - Pete - 04-25-2024 When I coded just a bit ago, I thought it might just need a hair cut, and it did! I think we both deserve a +1 for this effort! Pete RE: Alphabetical sort of characters within a string. - bplus - 04-25-2024 (04-25-2024, 01:40 AM)Pete Wrote: When I coded just a bit ago, I thought it might just need a hair cut, and it did! and steve's use of string was good too! RE: Alphabetical sort of characters within a string. - Circlotron - 04-25-2024 (04-25-2024, 01:28 AM)bplus Wrote: +1 that's pretty cool pete, here is quickerWow! That is off the planet! Thanks so much guys. Even though I've been messing with basic on and off since 1989, when I see some of the examples here I feel similar to when I watch some people playing guitar on youtube. Makes me wonder why i even try... BTW the purpose of this is to find anagrams in a long list of words. Thanks again. RE: Alphabetical sort of characters within a string. - CharlieJV - 04-25-2024 Code: (Select All) a$ = "this is uncopyrightable" RE: Alphabetical sort of characters within a string. - SMcNeill - 04-25-2024 (04-25-2024, 04:45 AM)Circlotron Wrote:You may also be interested in something such as this then: https://qb64phoenix.com/forum/showthread.php?tid=72(04-25-2024, 01:28 AM)bplus Wrote: +1 that's pretty cool pete, here is quickerWow! That is off the planet! Thanks so much guys. Even though I've been messing with basic on and off since 1989, when I see some of the examples here I feel similar to when I watch some people playing guitar on youtube. Makes me wonder why i even try... BTW the purpose of this is to find anagrams in a long list of words. Thanks again. That's my Scrabble Word List maker, which does a good ob making words from various combinations of letters. ![]() RE: Alphabetical sort of characters within a string. - bplus - 04-25-2024 (04-25-2024, 04:50 AM)CharlieJV Wrote: @CharlieJV almost same as Pete's only without instr both suffer from taking ucase$ or lcase$ more often than needed, asc can take a 2nd argument and work faster than mid$ for single letter. Code: (Select All) a$ = "this is uncopyrightable" i think instr will go faster than testing every letter in word 26 times. i am suspecting steve's or my mod of anacode$ with string$ will be faster than pete's using instr in alpha order, i like the fact we count over the length of word only once and there is no if testing when producing the return string from counts array. it is count len(word$) + 26 string alpha steps versus instr length of word and if find instr again and another if find... length of word x 2 ifs over 26 letters steps ie they both have to go 26 letter steps but no if's in steve's/my mod with string$. i will test by anacoding a dictionary with both methods, might consider throwing out the need for ucase$/lcase$ as entire dictionary is all capitals to start. RE: Alphabetical sort of characters within a string. - bplus - 04-25-2024 here are the 2 test routines written as functions check my optimizing Code: (Select All) _Title "anaCode$ versus peteCode$" ' b+ 2022-11-17 mod 2024-04-24 decodeAnacode sub RE: Alphabetical sort of characters within a string. - CharlieJV - 04-25-2024 (04-25-2024, 11:13 AM)bplus Wrote:(04-25-2024, 04:50 AM)CharlieJV Wrote: Yeah, I could have called UCASE$ once outside of the looping, but I was going for shortest amount of code vs performance. That said, UCASE$ x times for a single character vs UCASE$ 1 time for x characters, would there be a difference? Yeah, not in love with that second parameter for ASC. I'm a little bit too much old school there. RE: Alphabetical sort of characters within a string. - CharlieJV - 04-25-2024 How is ASC( ua$, j%) faster than MID$(a$,j%,1) ? Don't they have to do the same kind of work to get that one character in that one position? And if there is a benefit, is it being nullified by calling the extra CHR$ and the addition in the param? |