Solved

how can i convert character to ascii code and storing it in integer in C# .net window application??

Posted on 2011-02-23
11
568 Views
Last Modified: 2012-06-27
i want to convert character to ascii code and storing it into integer , but how can i do this ??

my coding is below ..

int i = Convert.ToInt16('a');

but i got error in it ??

what can i do ??
0
Comment
Question by:Parth48
11 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 125 total points
ID: 34959389
int c = (int)'a';
You can also use the Convert class
int c = Convert.ToInt32('a');
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 125 total points
ID: 34959392
Can you try the following

int asciiCode = (int)'a';
0
 
LVL 22

Assisted Solution

by:Ivo Stoykov
Ivo Stoykov earned 125 total points
ID: 34959396
Hi try this

HTH

Ivo Stoykov
int i = (int) 'a';

Open in new window

0
 
LVL 10

Assisted Solution

by:Asim Nazir
Asim Nazir earned 125 total points
ID: 34959409
THis is how it's:
int i = (int)'a';
Just cast the char to an integer and you have it (assuming the character actually comes from the ASCII set of characters).

Asim
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 34960061
If you mean that you want the character code in Unicode (not ASCII), then a character translates into an integer without the need for conversion or explicit casting:

  int i = 'a';

If you really want the ASCII code, you use the ASCII encoding:

  int i = Encoding.ASCII.GetBytes("a")[0];
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 11

Expert Comment

by:Sudhakar Pulivarthi
ID: 34960561
Hi,

There is no error in your code in this statement. It works perfect !!

int i = Convert.ToInt16('a');
The result in i is 97 after this statement.

Please check the error is doe to some other statement.
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 34969437
I have also given the same solution
0
 
LVL 10

Expert Comment

by:Asim Nazir
ID: 34969577
Even my solution was same with details :)
0
 

Author Comment

by:Parth48
ID: 34986059
please close this question ...

and give

Dhaest:
Can you try the following

int asciiCode = (int)'a';

full point ...

excellent ...
0
 

Expert Comment

by:South Mod
ID: 35015574
All,
 
Following an 'Objection' by pratima_mcs (at http://www.experts-exchange.com/Q_26844572.html) to the intended closure of this question, it has been reviewed by at least one Moderator and is being closed as recommended by the Expert.
 
At this point I am going to re-start the auto-close procedure.
 
Thank you,
 
SouthMod
Community Support Moderator
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now