Error decoding ISO character 147

  • Thread starter =?windows-1252?Q?Peter_Str=F8iman?=
  • Start date
?

=?windows-1252?Q?Peter_Str=F8iman?=

Hi

I have a byte-array, in which one of the bytes has the value 149 (hex95)
which represents a dot ( • ). The same character has the unicode value
of 8226 (hex 2022)

But when I try to decode the byte-array into a string, that character is
not converted into the correct value.

If I use the following code:

byte[] b = new byte[] { 147 };
char[] c = System.Text.Encoding.GetEncoding("ISO-8859-1").GetChars(b);

c now contains the character value 147 - which is an illegal unicode value.

What am I doing wrong (actually asp.net is doing it wrong as well,
because if I enter that character in a text-field, then the wrong value
is stored in the database. So the character is not properly decoded when
the form is posted to the server)

Regards,
Pete
 
?

=?windows-1252?Q?Peter_Str=F8iman?=

Peter said:
Hi

I have a byte-array, in which one of the bytes has the value 149 (hex95)
which represents a dot ( • ). The same character has the unicode value
of 8226 (hex 2022)

But when I try to decode the byte-array into a string, that character is
not converted into the correct value.

If I use the following code:

byte[] b = new byte[] { 147 };
char[] c = System.Text.Encoding.GetEncoding("ISO-8859-1").GetChars(b);

c now contains the character value 147 - which is an illegal unicode value.

What am I doing wrong (actually asp.net is doing it wrong as well,
because if I enter that character in a text-field, then the wrong value
is stored in the database. So the character is not properly decoded when
the form is posted to the server)

Regards,
Pete

Ahh - I was mistaken - 147 is not the ISO code for that character, it is
the windows-code for that particular character. So I guess my problem
now is, that my browser is using Windows-encoding instead of ISO when
posting the request.
 
M

Morten Wennevik

Well, you can test for Request.Encoding, or just swap your encoding with
Windows-1252


Peter said:
Hi
I have a byte-array, in which one of the bytes has the value 149
(hex95) which represents a dot ( • ). The same character has the
unicode value of 8226 (hex 2022)
But when I try to decode the byte-array into a string, that character
is not converted into the correct value.
If I use the following code:
byte[] b = new byte[] { 147 };
char[] c = System.Text.Encoding.GetEncoding("ISO-8859-1").GetChars(b);
c now contains the character value 147 - which is an illegal unicode
value.
What am I doing wrong (actually asp.net is doing it wrong as well,
because if I enter that character in a text-field, then the wrong value
is stored in the database. So the character is not properly decoded
when the form is posted to the server)
Regards,
Pete

Ahh - I was mistaken - 147 is not the ISO code for that character, it is
the windows-code for that particular character. So I guess my problem
now is, that my browser is using Windows-encoding instead of ISO when
posting the request.
 
G

Guest

I think I figured out that the root of my problem is that that
particular character does not exist at all in iso-8859-1. Therefore
ideologically the browser should not allow that character to be entered
- but it does.
I guess this is kinda like if someone entered Chinese characters into a
textbox. Those would be impossible to submit as well using ISO encoding.

But unfortunately the browser does not care that that particular
character is impossible to transmit using the specific encoding, and
transmits it anyway.

/Pete

Morten said:
Well, you can test for Request.Encoding, or just swap your encoding with
Windows-1252


Peter said:
Hi
I have a byte-array, in which one of the bytes has the value 149
(hex95) which represents a dot ( • ). The same character has the
unicode value of 8226 (hex 2022)
But when I try to decode the byte-array into a string, that
character is not converted into the correct value.
If I use the following code:
byte[] b = new byte[] { 147 };
char[] c = System.Text.Encoding.GetEncoding("ISO-8859-1").GetChars(b);
c now contains the character value 147 - which is an illegal unicode
value.
What am I doing wrong (actually asp.net is doing it wrong as well,
because if I enter that character in a text-field, then the wrong
value is stored in the database. So the character is not properly
decoded when the form is posted to the server)
Regards,
Pete

Ahh - I was mistaken - 147 is not the ISO code for that character, it
is the windows-code for that particular character. So I guess my
problem now is, that my browser is using Windows-encoding instead of
ISO when posting the request.



--Happy Coding!
Morten Wennevik [C# MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top