Jon
Fri Jan 25 15:22:50 CST 2008
Peter Duniho <NpOeStPeAdM@nnowslpianmk.com> wrote:
> On Fri, 25 Jan 2008 12:32:01 -0800, Arne Garvander
> <ArneGarvander@discussions.microsoft.com> wrote:
>
> > Dim B As Byte = 150
> > Dim C As Char
> > C = Convert.ToChar(B)
> > B = Asc(C)
> > And the value of B is 63
> > Why?
>
> Because 150 isn't a valid ASCII value (ASCII is 0 to 127). 63 is the
> ASCII code for a question mark ('?'), and that's what Asc is returning
> when you pass it a character that doesn't have a valid ASCII code.
To be strict about it, Asc is misnamed - it returns 63 when you pass it
a character which doesn't have a valid *ANSI* code for the default ANSI
code page on your system. Unfortunately there's a bad history of
assuming that ASCII==ANSI (and that ANSI is a specific encoding, rather
than a whole collection of them).
<shudders>
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
World class .NET training in the UK:
http://iterativetraining.co.uk