Alphabetizing Anyone? - 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: Alphabetizing Anyone? (/showthread.php?tid=2266) Pages:
1
2
|
Alphabetizing Anyone? - NakedApe - 12-20-2023 Happy holidays. I've sniffed around the site and can't find an alphabetizing routine. I doesn't have to be fast - I just need it to reorder some short files holding song titles. Any ideas for a guy looking for a simple sorter? Thanks! RE: Alphabetizing Anyone? - SMcNeill - 12-20-2023 I recommend _Memsort, if possible: https://qb64phoenix.com/forum/showthread.php?tid=75 Works on everything pretty much *except* variable length strings. (_Mem doesn't support variable length strings.) If you need a variable string sort instead, just let me know. I've got several of all shapes and models sitting around here in various places. RE: Alphabetizing Anyone? - NakedApe - 12-20-2023 (12-20-2023, 06:17 PM)SMcNeill Wrote: I recommend _Memsort, if possible: https://qb64phoenix.com/forum/showthread.php?tid=75Excellent, Steve. Thanks, I'll check it out. RE: Alphabetizing Anyone? - bplus - 12-20-2023 And for variable length strings in an array called sa$() (sa=String Array): Code: (Select All) DefLng A-Z RE: Alphabetizing Anyone? - NakedApe - 12-21-2023 Awesome. Thanks, bplus! RE: Alphabetizing Anyone? - mnrvovrfc - 12-21-2023 Code: (Select All) ReDim Shared sa$(1 To nItems) 'setup with string array sa$() shared so dont have to pass as parameter What if the user requires two string arrays to sort, and cannot copy or tamper with the only "sa$()" one? I'd rather take the example in QB64 Wiki, as slow and clunky as it might look. https://qb64phoenix.com/qb64wiki/index.php/SWAP (Example #3 but change array type to string.) RE: Alphabetizing Anyone? - SpriggsySpriggs - 12-21-2023 If I was still trying to peddle PowerShell scripts, I'd say use a text file and have PowerShell sort it for you and put it into a sorted file to be read. Or, use a file and have PowerShell output to stdout and use pipecom to read it in. RE: Alphabetizing Anyone? - TerryRitchie - 12-21-2023 When I have a small list of strings to sort I usually use this simple bubble sort. It's not fast but with small arrays of strings it's not even noticeable. Code: (Select All) 'simple bubble sort RE: Alphabetizing Anyone? - SpriggsySpriggs - 12-21-2023 For working in PowerShell: I have formatted them as if you are running it from inside a SHELL call in QB64. The carets (^) are needed to escape the pipe (|) characters. If you are running it already in PowerShell, you would get rid of "PowerShell -NoProfile" and the carets. If you want the directory listing of all text files sorted (PowerShell): Quote:PowerShell -NoProfile Get-ChildItem -Filter *.txt ^| Select Name -ExpandProperty Name ^| Sort-Object > sorted.txt If you already have a file with content inside of it (PowerShell): Quote:PowerShell -NoProfile Get-Content -Path examplefile.txt ^| Sort-Object > sorted.txt P.S The "-NoProfile" switch is necessary for PowerShell because there are profile scripts that are loaded when it is started that slow down execution considerably. "-NoProfile" tells it to ignore user settings which speeds up the call. P.P.S The redirect to sorted.txt is only necessary if you are not using pipecom. Without pipecom, you won't have access to the direct stdout handle. With it, you would remove that redirect and just grab the raw stdout from the call. RE: Alphabetizing Anyone? - NakedApe - 12-21-2023 Thanks, Terry and Spriggsy. |