Page 1 of 1

Custom Array Sorting

Posted: Tue Mar 26, 2013 8:49 am
by John
I need to sort an array by a customized order (with symbols and underscores after letters instead of before) What is the easiest way to do that?

-John

Posted: Tue Mar 26, 2013 9:56 am
by gtisdale
FNSNAP fnsrtary or fnsortarray

60320 DEF LIBRARY FNSRTARY(MAT L$;MAT M$,DESENDING,HEADER,FOOTER) !: ! Sorts MAT L$ in ascending order !: ! OPtionally based on MAT M$ !: ! In Descending order if DESending !: ! starting down from top to allow for a HEADER !: ! stopping before the bottom to allow for a FOOTER

or

04550 DEF LIBRARY FNSORTARRAY(MAT L$,START,LENGTH;DESENDING,HEADER,FOOTER) !: ! ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿!: ! ³ Sorts an array based on a substring within the array and ³!: ! ³ optionally omits lines at the top and bottom from the sort ³!: ! ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ!

Posted: Tue Mar 26, 2013 10:42 am
by John
Will these functions allow me sort in a custom order? I don't see any parameters for that.

I checked out the documentation for them on the BR Wiki.

http://brwiki.brulescorp.com/index.php? ... _Functions

They don't look like they will fit the bill, but maybe I'm missing something.

-John

Posted: Tue Mar 26, 2013 10:59 am
by gtisdale
By "Custom order" do you mean other than ASCII hiarchy? or do you mean a subset of positions within each string?

For example do you want all item that contain an "X" regardless of where it exxists in the string to sort before "A" and after "?".

If so you would need to build a separte array that contained some key to those and reference it in FNSRTARY as array M on which array L would be sorted.

Posted: Wed Mar 27, 2013 7:16 am
by John
Yes, I need to change it from regular ASCII order to one where symbols and underscores are after the letters instead of before.

Posted: Wed Mar 27, 2013 7:17 am
by John
I can write a routine to do it - I was just hoping there was some internal function I didn't know about... I hate to do work that doesn't need to be done, ya know. :)

Posted: Wed Mar 27, 2013 7:24 am
by gtisdale
I have not tried it, but have you attempted to create a COLLATE ALTERNATE file and used the CONFIG ALTERNATE ability?

Posted: Wed Mar 27, 2013 7:49 am
by John
Ooooooh - Good idea! I'll check that out! Thank you!