Click to See Complete Forum and Search --> : List Sorting


scathenC
December 11th, 2006, 09:03 PM
Hi all, this question doesn't relate directly to winapi but it can i suppose.
If you have any kind of list within windows and you sort the information,
number strings get arranged like this:

1
2
20
21
.
.
.
3
30
.
.

etc.

I was wondering if anyone knew a way around this style of sorting
that allows for this style of sorting:

1
2
3
4
.
.
.
10
11
.
.
20
21
.
.
etc.

I am trying to apply this to an index for my help file made in htmlhelp.
Is there any character or anything that I could use to change the way
text like this is sorted (I know i could just put zero's before the single
digit numbers but I don't want to)

Regards

C

Vanaj
December 11th, 2006, 09:28 PM
You can convert the strings to int's then do you own sort routine...

TheCPUWizard
December 11th, 2006, 09:37 PM
If you know the maximum number of digits (X), then you could also prepend X-1 zeros take the X rightmost characters and sort on that.

scathenC
December 11th, 2006, 09:49 PM
thanks for the replies.

Is there any invisible character that takes precedence over
numbers??

C

Vanaj
December 11th, 2006, 10:07 PM
thanks for the replies.

Is there any invisible character that takes precedence over
numbers??

C
A space would be a lesser value than any number...

TheCPUWizard
December 11th, 2006, 10:11 PM
Vanaj,

That is not necessarily a portable statement. You are assuming ASCII (or even the majority of UNICODE pages). I would either use the conversion or prepending of "0" technique for accomplishing the sorting..

Vanaj
December 11th, 2006, 10:18 PM
Vanaj,

That is not necessarily a portable statement. You are assuming ASCII (or even the majority of UNICODE pages). I would either use the conversion or prepending of "0" technique for accomplishing the sorting..

This is very true...about the ASCII...I used the conversion then wrote the sort routine...piece of cake...

I was kinda thinking about cleaning the string after the sort/display of the space with any of numerous routines to strip leading/trailing spaces, it just sounded easier than removing leading zeros from strings....good thought/point on your part.

scathenC
December 12th, 2006, 10:46 AM
That makes sense, but what if I can't access the data. It is for the
index of a help file built with htmlhelp!

C

VladimirF
December 12th, 2006, 03:15 PM
... but what if I can't access the data. It is for the
index of a help file built with htmlhelp!
Then you can write a Compare() function and use numerical compare in it, then send a LVM_SORTITEMS message. That is, if you use ListControl...