Click here to Skip to main content
15,886,724 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

Ordinal suffixes in English for the nth degree

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
14 Jun 2011CPOL 9.9K   1   2
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


C#
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 :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO VISION fOr VISION
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralThanks Pin
YDaoust14-Jun-11 1:43
YDaoust14-Jun-11 1:43 
GeneralExcellent. And the crypticism gets balanced very well by the... Pin
Luc Pattyn14-Jun-11 1:20
sitebuilderLuc Pattyn14-Jun-11 1:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.