Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, June 4, 2007 9:59 AM | 1 vote
hi
i need help in converting number to alphabet
for example 4 to D, 2 to B, etc
thank you for helping
best regards
andors
All replies (8)
Monday, June 4, 2007 10:09 AM âś…Answered | 3 votes
use the following code...
Code Snippet
private String Number2String(int number, bool isCaps)
{
Char c = (Char)((isCaps ? 65 : 97) + (number - 1));
return c.ToString();
}
Tuesday, June 5, 2007 12:18 AM
It works ......
Thank you so much
best regards
andors
Sunday, August 28, 2011 10:15 AM
Could you please convert number to Roman numerals ?
Thanks
Monday, August 29, 2011 9:47 AM
http://www.mgbrown.com/PermaLink88.aspx
Tuesday, May 14, 2013 9:27 AM
how can i made this in foxpro i want to do the same like that but i'm using foxpro 9.thank you
Friday, June 21, 2013 1:33 PM
Thank you.. it works
Thursday, July 17, 2014 11:52 AM
would you please explain this code how to convert num to alphabet....
Monday, December 29, 2014 9:23 PM
private String Number2String(int number, bool isCaps)
{
Char c = (Char)((isCaps ? 64 : 96) + number);
return c.ToString();
}
No point in doing - 1.
If you want 0 to be A then start at 65 for caps, 97 for lower.
Edit:
After some messing around, I've come up with the perfect method:
public static string numberToAlpha(long number, bool isLower = false)
{
string returnVal = "";
char c = isLower ? 'a' : 'A';
while (number >= 0)
{
returnVal = (char)(c + number % 26) + returnVal;
number /= 26;
number--;
}
return returnVal;
}