algorithm - Simplest way to do "natural" sort for numbers in strings? -
i saw this , wondering best way implement natural sorting this?
usually in list of 1,4,11,12
string sort (used in listing items) returns 1,11,12,4
. how implement natural ordering?
the items can
[ 'screen 4 episode 13', 'screen 11 episode 1', .... ]
for above mentioned list , sample list provided in question, following method can used:
convert number in elements bucket based system, i.e calculate maximum of digit in of string. example in above list, value 2. convert numbers in elements in such way length turns out of length same maximum. therefore,'screen 4 episode 13' converted 'screen 04 episode 13' , 'screen 11 episode 1' converted 'screen 11 episode 01'.
now sort modified list string.
Comments
Post a Comment