Created
November 17, 2010 00:23
-
-
Save Nemo157/702784 to your computer and use it in GitHub Desktop.
Converts integers to ordinal strings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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