Home All Groups Group Topic Archive Search About

Error decoding ISO character 147

Author
22 Sep 2006 11:31 AM
Peter_Strøiman
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

Author
22 Sep 2006 12:00 PM
Peter_Strøiman
Peter Strøiman wrote:
Show quote
> 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.
Author
22 Sep 2006 1:03 PM
Morten Wennevik
Well, you can test for Request.Encoding, or just swap your encoding with 
Windows-1252


On Fri, 22 Sep 2006 14:00:03 +0200, Peter Strøiman 
<peterstroeiman@nospam.nospam> wrote:

Show quote
> Peter Strøiman wrote:
>> 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]
Author
25 Sep 2006 8:33 AM
Peter Strøiman
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 Wennevik wrote:
Show quote
> Well, you can test for Request.Encoding, or just swap your encoding with
> Windows-1252
>
>
> On Fri, 22 Sep 2006 14:00:03 +0200, Peter Strøiman
> <peterstroeiman@nospam.nospam> wrote:
>
>> Peter Strøiman wrote:
>>> 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]

AddThis Social Bookmark Button