Be carrefull with System.Text.ASCIIEncoding.ASCII.GetString(b);
If your codepage is different than English then the conversion could have
problems (not always).
I had this problem where I had a program running on Korea where the codepage
where different and then the range of Extended ASCII characters supported
are from 0 to 239, instead 0 to 255.
I experimented this problem with some Windows installed on different
languages.
If you want get a string back you can use something like this.
System.Text.Encoding.GetEncoding(1251).GetString(b ); (1251 is English)
You can see how the conversion fail if you go to Control Panel, Regional
Settings, Advanced and on "Language for non-Unicode programs" put Japanese.
The strange thing is: clearly it says: "Language for non-Unicode programs",
I know .net is full Unicode.
Now, why using System.Text.ASCIIEncoding.ASCII fail?, I don't know that...
Really doesn't fail, but if you Encode a string with extended characters
into bytes and Decoded again into string, you will get different results. I
guess .net map the extended character to the near one supported for the
codepage.
Gustavo.
"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:OA**************@TK2MSFTNGP12.phx.gbl...
"pkumar" <pk****@discussions.microsoft.com.> wrote in message
news:AE**********************************@microsof t.com... How to convert this byte array to string
byte[] b=new byte[100];
Is there any function or I need read one by one and build the string
thanks
byte[] b = new byte[100];
string s = System.Text.ASCIIEncoding.ASCII.GetString(b);
HTH,
Mythran