Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Converting Char to ASCII

Reply
Thread Tools

Converting Char to ASCII

 
 
=?Utf-8?B?ZG90bmV0dGVzdGVy?=
Guest
Posts: n/a
 
      08-15-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
 
      08-15-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
 
      08-15-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:(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
 
      08-15-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
 
      08-17-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
(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
reading binary file into memory. Converting from char to uint32,float, double, ASCII strings etc (static_cast< > ?) someone C++ 37 10-18-2011 01:32 AM
Beginner User having issue with converting char to ASCII Nick Bo Ruby 8 10-30-2009 04:57 AM
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
Converting char* to char Chris Online C++ 11 02-19-2004 08:55 AM



Advertisments