At the moment empty strings at the beginning: "", "1", "A", "B"
Would nice to have on option to sort empty strings at the bottom of the list: "1", "A", "B", ""
New flag fort sort functions: #PB_Sort_EmptyLast
Re: New flag fort sort functions: #PB_Sort_EmptyLast
Incorrect example removed. See new post further below.
Last edited by BarryG on Sat Jan 11, 2020 1:35 pm, edited 1 time in total.
Re: New flag fort sort functions: #PB_Sort_EmptyLast
@BarryG
This is only in your example, because the blanks are already at positions 9+10 and you only sort the first 8 positions. Here isn't so:
However, I think it is not a big effort to move the empty strings 'manually' to the end.
This is only in your example, because the blanks are already at positions 9+10 and you only sort the first 8 positions. Here isn't so:
Code: Select all
ten=10
Dim a$(ten)
a$(1) = "A"
a$(2) = "D"
a$(3) = "H"
a$(4) = "R"
a$(5) = ""
a$(6) = "S"
a$(7) = "S"
a$(8) = "U"
a$(9) = ""
a$(10) = "V"
SortArray(a$(),#PB_Sort_Ascending,1,8) ; ",1,8" forces blanks to the bottom.
For a=1 To ten
Debug ">"+a$(a)+"<"
Next
However, I think it is not a big effort to move the empty strings 'manually' to the end.
sorry for my bad english
Re: New flag fort sort functions: #PB_Sort_EmptyLast
Right. I totally overlooked that.
Here's two (hacky and probably slow) solutions, so I agree #PB_Sort_EmptyLast is a good wish!
This one does the request and keeps the same number of elements:
And this one does the request but reduces the number of elements by removing the empty elements:
Take your pick, Lebostein.
Here's two (hacky and probably slow) solutions, so I agree #PB_Sort_EmptyLast is a good wish!
This one does the request and keeps the same number of elements:
Code: Select all
count=10
Dim a$(count)
a$(1) = "Z"
a$(2) = "D"
a$(3) = "B"
a$(4) = "R"
a$(5) = ""
a$(6) = "S"
a$(7) = "A"
a$(8) = "U"
a$(9) = ""
a$(10) = "E"
SortArray(a$(),#PB_Sort_Descending)
For n=1 To count
If a$(n)=""
ReDim a$(n)
SortArray(a$(),#PB_Sort_Ascending)
ReDim a$(count)
Break
EndIf
Next
For a=1 To count
Debug ">"+a$(a)+"<"
Next
Code: Select all
count=10
Dim a$(count)
a$(1) = "Z"
a$(2) = "D"
a$(3) = "B"
a$(4) = "R"
a$(5) = ""
a$(6) = "S"
a$(7) = "A"
a$(8) = "U"
a$(9) = ""
a$(10) = "E"
SortArray(a$(),#PB_Sort_Descending)
For n=1 To count
If a$(n)=""
ReDim a$(n)
SortArray(a$(),#PB_Sort_Ascending)
count=n
Break
EndIf
Next
For a=1 To count
Debug ">"+a$(a)+"<"
Next
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: New flag fort sort functions: #PB_Sort_EmptyLast
... if and only if the option #PB_Sort_Ascending is used.Lebostein wrote:At the moment empty strings at the beginning: "", "1", "A", "B"
Naming the additionally wanted flag #PB_Sort_EmptyLast wouldn't be a good idea, because PB puts empty strings at the end anyway when the option #PB_Sort_Descending is used.Lebostein wrote:New flag fort sort functions: #PB_Sort_EmptyLast
A more logical name would be e.g. #PB_Sort_EmptyOpposite:
- put empty strings at the end when sorting ascending
- put empty strings at the beginning when sorting descending
I posted a procedure SortStringArraySpecial() that does the job.