patrivet Posted August 13, 2007 Share Posted August 13, 2007 Hello,I am wondering if anyone has been able to use the <sort> function, or another method, to sort alpha numeric strings, compared to just character strings? as I see the sort function only handles character sorting. Thanks Link to comment Share on other sites More sharing options...
boen_robot Posted August 13, 2007 Share Posted August 13, 2007 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 More sharing options...
patrivet Posted August 14, 2007 Author Share Posted August 14, 2007 Specifically I am sorting values that follow this pattern:-alan-pb-1001alan-pb-1342alan-pb-34alan-pb-48etc etc Link to comment Share on other sites More sharing options...
patrivet Posted August 14, 2007 Author Share Posted August 14, 2007 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 More sharing options...
boen_robot Posted August 14, 2007 Share Posted August 14, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.