65.9K
CodeProject is changing. Read more.
Home

Ordinal suffixes in English for the nth degree

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Jun 14, 2011

CPOL
viewsIcon

10352

What aboutpublic static string NUMthOF(UInt32 v){ return v.ToString() + // Append the ordinal suffix for the unit digit // unless the ten digit is a one (force 'th') "thstndrdthththththth".Substring(2 * (int)(v / 10 % 10 != 1 ? v % 10 : 0), 2);}?Now all...

What about

public static string NUMthOF(UInt32 v)
{
    return v.ToString() + 
        // Append the ordinal suffix for the unit digit
        // unless the ten digit is a one (force 'th')
        "thstndrdthththththth".Substring(2 * (int)(v / 10 % 10 != 1 ? v % 10 : 0), 2);
}

?

Now all the crypticism is concentrated in a single expression :)