Showing posts with label sorting. Show all posts
Showing posts with label sorting. Show all posts

Saturday, 4 May 2013

Workaround about sorting English ordinal numbers or Roman numbers

You may want to sort texts containing English ordinal numbers or Roman numbers by their numerical order instead of dictionary order. For example

1st word
2nd word
3rd word
4th word

Richard I
Richard II
Richard III
Richard IV

One simple workaround for this is to encode them as simple numbers in the text, e.g.

#T001 word
#T002 word
#T003 word
#T004 word

Richard #R01
Richard #R02
Richard #R03
Richard #R04

then they can be sorted by dictionary order. When you need to display them, convert them to ordinal number or Roman number.