Page 1 of 1
sorting fixed strings. not important, just curiosity
Posted: Wed Oct 30, 2024 6:26 am
by noxidderf
was reading the help file and i saw that "Fixed strings are not supported by the sort routine."
I am not using one at the moment but I keep thinking about it.
I searched some but I did not read anything touching on my question.
I am wondering why it is not possible ? just curiosity, not looking for a indepth explanation.
is that something I would need to figure out how to do if I run into it,
I might be just being dumb here. I get stuck on these questions from time to time.
Fred, it is finally cooling off here. (-:
Re: sorting fixed strings. not important, just curiosity
Posted: Wed Oct 30, 2024 7:01 am
by RASHAD
Hi
Maybe you can use ListIcon() gadget populate it with your strings then sort it
I can't tell about MAC or Linux but it works with Windows

Re: sorting fixed strings. not important, just curiosity
Posted: Wed Oct 30, 2024 8:07 am
by wilbert
You can use CustomSortArray() to sort fixed strings.
Code: Select all
Structure FS10
s.s{10}
EndStructure
Procedure CompareFS10(*a.FS10, *b.FS10)
ProcedureReturn CompareMemoryString(*a, *b, #PB_String_NoCase, 10)
EndProcedure
Dim s.s{10}(4)
s(0)="GHI"
s(1)="abc"
s(2)="MNO"
s(3)="JKL"
s(4)="DEF"
Debug "Unsorted"
For i=0 To 4
Debug s(i)
Next
Debug ""
CustomSortArray(s(), @CompareFS10(), #PB_Sort_Ascending)
Debug "Sorted"
For i=0 To 4
Debug s(i)
Next
Re: sorting fixed strings. not important, just curiosity
Posted: Wed Oct 30, 2024 1:56 pm
by noxidderf
I lay back after my alarm went off this morning., and thought about my question.
It is just a block of memory with the fixed string information in one long block I would guess.
Wow, so many functions. I had not run across those yet. I am blown away with all the connivance.
thanks for pointing out the customsorts.
Re: sorting fixed strings. not important, just curiosity
Posted: Wed Oct 30, 2024 4:03 pm
by noxidderf
question about the example.
the length of the strings is 4 for 3 letters/symbols, is that to account for the 0 strings terminator ?
Re: sorting fixed strings. not important, just curiosity
Posted: Wed Oct 30, 2024 4:21 pm
by wilbert
noxidderf wrote: Wed Oct 30, 2024 4:03 pm
the length of the strings is 4 for 3 letters/symbols, is that to account for the 0 strings terminator ?
A fixed string always occupies the maximum string length in memory.
The maximum length of each
.s{10} string is 10 characters. I just didn't use all 10 of them.
The 4 in
Dim s.s{10}(4) is the size of the array.
PureBasic uses the highest index (starting from 0) instead of the true array size so in this case the array contains 5 items (0 .. 4).
Re: sorting fixed strings. not important, just curiosity
Posted: Wed Oct 30, 2024 4:30 pm
by AZJIO
noxidderf wrote: Wed Oct 30, 2024 4:03 pm
question about the example.
the length of the strings is 4 for 3 letters/symbols, is that to account for the 0 strings terminator ?
Code: Select all
Dim s.s{3}(4)
s(0)="abc"
s(1)="def"
s(2)="ghi"
s(3)="jkl"
s(4)="mno"
Debug PeekS(@s(0), 3*5)
Debug PeekS(@s(0), 3 * (ArraySize(s()) + 1))
Another example
Code: Select all
arrsize = 8
#StrLength = 3
Dim s.s{#StrLength}(arrsize)
Define *t.Character
*t = @s(0)
For i = Abs('A') To Abs('A') + (arrsize + 1) * #StrLength ; Abs('z')
*t\c = i
*t + SizeOf(Character)
Next
For i = 0 To ArraySize(s())
Debug Str(i) + " " + s(i)
Next
Re: sorting fixed strings. not important, just curiosity
Posted: Thu Oct 31, 2024 12:03 am
by noxidderf
got it, thanks. I needed coffee this morning.