Talk:Natural sorting: Difference between revisions

→‎Numeric sub-fields: Split then compare all fields from the right
(→‎Why draft?: Ambiguities…?)
(→‎Numeric sub-fields: Split then compare all fields from the right)
Line 8:
:: --[[User:Paddy3118|Paddy3118]] 12:20, 23 April 2011 (UTC)
 
== Numeric sub-fields ==
For the fourth one (numeric sub-fields), are we to ignore the non-numeric parts or to assume they're the same? –[[User:Dkf|Donal Fellows]] 17:28, 23 April 2011 (UTC)
 
No field is ignored Donal.
# Split the string into fields of alternating numeric/non-numeric runs of characters (or non-numeric/numeric).
# when comparing two strings s1 and s2 say, now split as fields, start from the rightmost fields and compare them - if the first fields are numeric then compare them as integers; if the fields are both non-numeric then compare them as character strings; if they differ in type then assume any integer field is always less than any non-integer field (the two strings shouldn't really be compared, but this gives them a defined order).
# If the two rightmost fields are equal then compare the next two fields, and so on.
# If the fields of the two strings compare equal so far, but one string has no more fields but the other has more fields, then the string with least fields is the smaller.
Using the above comparison rules you should be able to sort/order strings. --[[User:Paddy3118|Paddy3118]] 19:11, 23 April 2011 (UTC)
Anonymous user