Link to home
Start Free TrialLog in
Avatar of MarissaShannon
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!
Avatar of UnexplainedWays
UnexplainedWays

char startChar = 'a';
        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();
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();
ASKER CERTIFIED SOLUTION
Avatar of Yurich
Yurich
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dmitry G
Yeah... The function should return integer, not some string. Why "<br> in the string!?

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
Hi,

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
Avatar of MarissaShannon

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