SYSK 66: .NET 1.1 and 2.0 Handles ASCII Encoding Differently?
My tests show that the answer is Yes… See it for yourself.
Create a windows app in VS 2003, add one text box and one button to a form and put the following code behind the button click:
// A bunch of bytes represented by their code
string[] input = "98 22 248 167 95 213 187 61 95 34 182 249 149 140 222 222 63 192 134 194".Split(' ');byte[] byteData = new byte[input.Length];
for (int i = 0; i < byteData.Length; i++ )
{
byteData[i] = (byte) int.Parse(input[i]);
}// this works the same in 1.1 and 2.0
//textBox21Text = System.Text.Encoding.UTF8.GetString(byteData);// this works the same in 1.1 and 2.0
//textBox1.Text = System.Text.Encoding.Unicode.GetString(byteData);// this is where the problem surfaces
textBox1.Text = System.Text.Encoding.ASCII.GetString(byteData);
Now, do exactly the same in VS 2005.
Run both applications, click the button and compare the results in the text box. If you want to go fancy, add a second text box and a second button to VS 2005 project and do the comparison in code as follows:
if (textBox1.Text == textBox2.Text)
MessageBox.Show("Ok. Same.");
else
MessageBox.Show("Not the Same!");
Then, simply copy and paste VS2003’s text box data in text box 2 of VS 2005 project and click the second button to see the results…
Comments
Anonymous
February 21, 2006
I don't have vs2005 or .net 2.0.. is it possible you can post what System.Text.Encoding.ASCII.GetString(byteData);
returns in 2.0?Anonymous
February 23, 2006
I'm getting an error posting the reply due to non-printable characters. If interested, send me an e-mail, and I'll reply directly.Anonymous
March 09, 2006
The comment has been removedAnonymous
February 13, 2007
The comment has been removedAnonymous
April 11, 2007
The comment has been removedAnonymous
April 11, 2007
The comment has been removed