Skip to content

Instantly share code, notes, and snippets.

@Nemo157
Created November 17, 2010 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nemo157/702784 to your computer and use it in GitHub Desktop.
Save Nemo157/702784 to your computer and use it in GitHub Desktop.
Converts integers to ordinal strings.
public static class MyExtensions
{
public static String ToOrdinalString(this Int32 num)
{
switch (num % 100)
{
case 11:
case 12:
case 13:
return num.ToString() + "th";
}
switch (num % 10)
{
case 1:
return num.ToString() + "st";
case 2:
return num.ToString() + "nd";
case 3:
return num.ToString() + "rd";
default:
return num.ToString() + "th";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment