.NETGURU
Cast to ascii and back.
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcs' list.


Stewart Haddock
Hello,

How do I cast a character to it's ascii equivilant? And then cast it back?

iA = (asc)"A"; //?
iZ = int.Parse("Z"); //?

sA = (char)iA; //?
sZ = (char)iZ; //?

Thanks,

Stewart Haddock

Reply to this message...
 
    
Ken Meads
int l_a = 'a';
char c_a = (char)l_a;

l_a will contain the ascii value of the character 'a'.
c_a simply casts it back to the letter 'a'.

If you were to apply the following code:
Console.WriteLine("l_a == {0}", l_a);
Console.WriteLine("c_a == {0}", c_a);
you would get the following output:
l_a == 97
c_a == a

Hope that helps...

"Stewart Haddock" <Click here to reveal e-mail address> wrote in message
news:677230@aspngcs...
[Original message clipped]

Reply to this message...
 
    
Joshua Perry
You have to remember though that .NET uses double byte characters and
all ascii characters will be 16 bit with the first 8 bits as 0's. To
change to 7-bit ascii use the System.Text.Encoding namespace.

Joshua Perry
1-800 CONTACTS, INC.
Information Systems Developer
(801)924-9828
=20

-----Original Message-----
From: Ken Meads [mailto:Click here to reveal e-mail address]=20
Sent: Monday, July 01, 2002 10:10 AM
To: aspngcs
Subject: [aspngcs] Re: Cast to ascii and back.

int l_a =3D 'a';
char c_a =3D (char)l_a;

l_a will contain the ascii value of the character 'a'.
c_a simply casts it back to the letter 'a'.

If you were to apply the following code:
Console.WriteLine("l_a =3D=3D {0}", l_a);
Console.WriteLine("c_a =3D=3D {0}", c_a);
you would get the following output:
l_a =3D=3D 97
c_a =3D=3D a

Hope that helps...

"Stewart Haddock" <Click here to reveal e-mail address> wrote in message
news:677230@aspngcs...
[Original message clipped]

| [aspngcs] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp =3D JOIN/QUIT

Reply to this message...
 
 
System.Console
System.Text.Encoding




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification