Jump to content

Alpha Numeric sort


patrivet

Recommended Posts

Exactly what do you have in mind? I mean, you could either sort numbers, where the sequence151020will appear in this order, or you could sort strings in which case the above would be sorted as110205as strings are sorted by first putting prior first characters at top, later at bottom, and then do the same for each next character keeping it in this range. Numbers are just compared.So what do you mean by "sorting alphanumeric strings"? Sorting them is the same as sorting numbers as strings. The sequencea1a10a20a5could only appear in this order. The only possible way around it is to keep the number and string separate (in two different nodes) and sort only by those numbers, ideally concatenating them with the string in the output only.

Link to comment
Share on other sites

So, yes <sort> does not handle sorting with numbers and strings. I am not sure I can predict where the numbers in my string will begin at every occasion, so I cannot easily chop the variable into two and sort on the numbers and strings separately...

Link to comment
Share on other sites

There must be some way. If the XML is generated dynamically, you could try to predict where the numbers are upon entering and place them in their own node at that point. Ideally, you'll need a way to convert

<element>alan-pb-1001</element>

to either

<element>alan-pb-<n>1001</n></element>

or

<element>alan-pb-<n/>1001</element>

I reccomend the first, as it's more flexible for the price of being slightly more verbose.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...