Finding the English alphabetic order of a character
http://forums.asp.net/thread/1637908.aspx
This was an interesting post to me, as I haven't peeked around .Net's simple data types much. I came up with the following:
C#:
int GetOrdinal(char c)
{
return ((c.CompareTo('a') < 0) ? c.CompareTo('a') + 33 :
c.CompareTo('a') + 1);
}
VB.Net
Function GetOrdinal(ByVal c As Char) As Integer
Return IIf((c.CompareTo("a"c) < 0), c.CompareTo("a"c) + 33, c.CompareTo("a"c) + 1)
End Function
1 Comments:
Great work.
Post a Comment
<< Home