PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

Converting Char to ASCII

 
 
=?Utf-8?B?ZG90bmV0dGVzdGVy?=
Guest
Posts: n/a
 
      15th Aug 2005
Hi,
In old asp I would just juse ASC('a') and that would give me the ASCII code
of that character, How can I do this in ASP.net

Having trouble finding the right class.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?ZG90bmV0dGVzdGVy?=
Guest
Posts: n/a
 
      15th Aug 2005
I mean ANSI code

"dotnettester" wrote:

> Hi,
> In old asp I would just juse ASC('a') and that would give me the ASCII code
> of that character, How can I do this in ASP.net
>
> Having trouble finding the right class.

 
Reply With Quote
 
Chris Taylor
Guest
Posts: n/a
 
      15th Aug 2005
Hi,

You did not specify the language so I will assume C#, a simple cast will do
the job
int c = (int)'a';
You can also use the Convert class
int c = Convert.ToInt32('a');

For VB.NET the Convert class will work or you can use the VB.NET
implementation of Asc().

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor


"dotnettester" <(E-Mail Removed)> wrote in message
news:766F6375-D7F3-4E88-AB08-(E-Mail Removed)...
> Hi,
> In old asp I would just juse ASC('a') and that would give me the ASCII

code
> of that character, How can I do this in ASP.net
>
> Having trouble finding the right class.



 
Reply With Quote
 
jasonkester
Guest
Posts: n/a
 
      15th Aug 2005
Don't forget the usual caveat that the above only works for ASCII
values between 1 and 127. Above that, and into Unicode, all bets are
off.

This doesn't matter for most practical applications, but do some
digging in this group for some amusing theological battles on this
topic.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

 
Reply With Quote
 
Joerg Jooss
Guest
Posts: n/a
 
      17th Aug 2005
Chris Taylor wrote:

> Hi,
>
> You did not specify the language so I will assume C#, a simple cast
> will do the job
> int c = (int)'a';
> You can also use the Convert class
> int c = Convert.ToInt32('a');
>
> For VB.NET the Convert class will work or you can use the VB.NET
> implementation of Asc().
>
> Hope this helps


This will return the character's Unicode codepoint, which is not
necessarily the same as the character's byte value in ANSI encoding --
whatever that's suppoed to be. Windows-1250? -1251? -1252?

To encode characters, use a appropriate System.Text.Encoding instance
instead

Cheers,
--
http://www.joergjooss.de
mailto:news-(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ascii value of char. in C# sajit Microsoft ASP .NET 1 7th Apr 2007 06:37 AM
ascii char set dotnetchic Microsoft C# .NET 2 15th Mar 2006 01:54 PM
Converting from Char to ASCII glenn Microsoft C# .NET 2 28th Apr 2005 06:37 PM
Re: Ascii to char Herfried K. Wagner [MVP] Microsoft VB .NET 0 19th Jul 2004 12:35 PM
(unsafe) Converting char*[] -> char** for PInvoke call Adam Clauss Microsoft C# .NET 1 28th Apr 2004 10:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:31 AM.