Sort an attribute - string

Dear all,
I am trying to figure out how to sort an attribute type with string.
The attribute column has 1, 2, 3, 3.1, 4.2, 10, but, if I use sort, it show 1, 10, 2, etc.
I have a query to pull certain notes, and I want the action to sort the notes in the order of 1, 2, 3, 3.1, 4.2, 10. Could you please help? I have tried sort, nsort, but in vain.

Thank you.

Multi-item value (List and Set data types) are stored as strings. The default sort is lexical which sorts numbers 1, 10, 2 not 1, 2, 10: more on lexical vs. numerical sort.

As Set-type resorts (in A-Z order) automatically you can’t force a set to store/display (e.g. in Displayed Attributes tables) its data in numerical form as the auto-sort will overwrite your other sorting.

So numerical sorts only work in List-type attributes. To do this use a number-sort: see List.nsort()

Does that help?

1 Like

OK: you’ve got an agent that’s collecting notes, and these notes have some attribute that has values like “1” and “3.1”.

From your difficulty, I surmise that these are stored as string attributes — perhaps section numbers? If so, Tinderbox sorts things lexicographically — as strings.

But that’s not what you want! OK: one easy trick here would be to convert the section number to a number:

OnAdd: $MyNumber=$Section

Where “Section” is the name of the attribute that’s causing the headache. Now, sorting on MyNumber should do the trick!

This would run into trouble if some of the sections didn’t have any section number, such as “Preface” or “Appendix XII”. We can deal with such things, too, but let’s cross that bridge when we come to it.

1 Like

Thank you very much. Worked like a charm.
Apology for late reply.

1 Like

Thank you Mark. Much appreciated. Apology for the late reply.

1 Like