MarissaShannon
asked on
Convert ascii character into its decimal number in ascii table
I want to write a simple conversion program. It's used to convert a character into its decimal number in ascii table!
For example
When user types 'a', the program will return its decimal number in ascii table known as 97.
Can anyone give me any suggestion or solution to this???
Thanks a lot!
P/S: I am using Visual C# in Visual Studio 2005 to program!
For example
When user types 'a', the program will return its decimal number in ascii table known as 97.
Can anyone give me any suggestion or solution to this???
Thanks a lot!
P/S: I am using Visual C# in Visual Studio 2005 to program!
or you could get all of them
System.Text.StringBuilder sb = new System.Text.StringBuilder( );
for (int theChar = 1; theChar <= 255; theChar++)
{
sb.Append((char)theChar + " = " + theChar.ToString() + "<br>");
}
results.Text = sb.ToString();
System.Text.StringBuilder sb = new System.Text.StringBuilder(
for (int theChar = 1; theChar <= 255; theChar++)
{
sb.Append((char)theChar + " = " + theChar.ToString() + "<br>");
}
results.Text = sb.ToString();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yeah... The function should return integer, not some string. Why "<br> in the string!?
Yurich, simple and elegant! :)
Yurich, simple and elegant! :)
"ascii table!"
Ah i thought they wanted a way to display all of them in a table. So they could then take out the br and wack in the td's
Ah i thought they wanted a way to display all of them in a table. So they could then take out the br and wack in the td's
Hi,
private int CharToAscii(char a)
{
return (int)a;
}
Regards
DivyeshhDoshi
private int CharToAscii(char a)
{
return (int)a;
}
Regards
DivyeshhDoshi
"... For example
When user types 'a'..."
You can't get an actual char from a user - it will be a string, whether it's console, windows, or web application. Hence getting a char from a string first...
Cheers,
Yurich
When user types 'a'..."
You can't get an actual char from a user - it will be a string, whether it's console, windows, or web application. Hence getting a char from a string first...
Cheers,
Yurich
ASKER
Thanks all, and I have caught all your ideas. However, the answer of Yurich is the most close and useful for my application! 2 others also have the same idea but there are not enough abstract for me to use!
You're welcome, but can you explain why it's B grade? What else would you like to see in my answer that would make you put an A? Was it not timely or accurate? Please explain.
Regards,
Yurich
Regards,
Yurich
char endChar = 'z';
System.Text.StringBuilder sb = new System.Text.StringBuilder(
for (int theChar = (int)startChar; theChar <= (int)endChar; theChar++)
{
sb.Append((char)theChar + " = " + theChar.ToString() + "<br>");
}
results.Text = sb.ToString();