How to retrun a character with ascii code

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

How to retrun a character with ascii code?
It is useChr(65) return 'A' in VB.NET.
What is the equivalent function in C#?
 
Hi Ad,

char[] characters = System.Text.Encoding.ASCII.GetChars(new byte[] {65});

Yes, looks quite cumbersome and I wonder myself why there is no overload for
a single character (or was I just too lazy to dig MSDN enough? ;-)
 
Hallo!

Hi Ad,

char[] characters = System.Text.Encoding.ASCII.GetChars(new byte[]
{65});

Yes, looks quite cumbersome and I wonder myself why there is no
overload for a single character (or was I just too lazy to dig MSDN
enough? ;-)

Why not Convert.ToChar(65) ?

Sincerely

Oskar
 
Oskar said:
Hallo!

Hi Ad,

char[] characters = System.Text.Encoding.ASCII.GetChars(new byte[]
{65});

Yes, looks quite cumbersome and I wonder myself why there is no
overload for a single character (or was I just too lazy to dig MSDN
enough? ;-)

Why not Convert.ToChar(65) ?

char c = (char) 65;

works as well, though I consider it less readable.

Cheers,
 
Hallo Oskar,

I think Convert.ToChar as well as (char)65 assume the Unicode encoding,
while the author has explicitly mentioned the ASCII one.
Yes, the character codes of the capital 'A' are the same in both of the
encodings, but this, in general, might be not true for other character codes
and other encodings.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


Oskar Punz said:
Hallo!

Hi Ad,

char[] characters = System.Text.Encoding.ASCII.GetChars(new byte[]
{65});

Yes, looks quite cumbersome and I wonder myself why there is no
overload for a single character (or was I just too lazy to dig MSDN
enough? ;-)

Why not Convert.ToChar(65) ?

Sincerely

Oskar
 
Hi!

Hallo Oskar,

I think Convert.ToChar as well as (char)65 assume the Unicode
encoding, while the author has explicitly mentioned the ASCII one.
Yes, the character codes of the capital 'A' are the same in both of
the encodings, but this, in general, might be not true for other
character codes and other encodings.

AFAIK the first 128 Unicode characters are the same as the
ASCII characters (except an extra leading zero byte).

So as long as you don't use values above 127 nothing
can go wrong. Right?

Ciao

Oskar
 
Back
Top