?
Solved

Convert ascii character into its decimal number in ascii table

Posted on 2007-07-23
9
Medium Priority
?
5,834 Views
Last Modified: 2013-12-17
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!
0
Comment
Question by:MarissaShannon
9 Comments
 
LVL 12

Expert Comment

by:UnexplainedWays
ID: 19552731
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();
0
 
LVL 12

Expert Comment

by:UnexplainedWays
ID: 19552735
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();
0
 
LVL 21

Accepted Solution

by:
Yurich earned 375 total points
ID: 19552748
wow, that looks a bit overcomplicated... what about this one?

private int CharToAscii( string letter )
{
      return ( int )( ( char )letter[ 0 ] );
}

Cheers,
Yurich
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 19552812
Yeah... The function should return integer, not some string. Why "<br> in the string!?

Yurich, simple and elegant! :)
0
 
LVL 12

Expert Comment

by:UnexplainedWays
ID: 19552832
"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
0
 
LVL 6

Expert Comment

by:divyeshhdoshi
ID: 19554727
Hi,

private int CharToAscii(char a)
{
           return (int)a;
}

Regards
DivyeshhDoshi
0
 
LVL 21

Expert Comment

by:Yurich
ID: 19554804
"... 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
0
 

Author Comment

by:MarissaShannon
ID: 19556568
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!
0
 
LVL 21

Expert Comment

by:Yurich
ID: 19558671
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
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question