UTF8 encoding problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SloppyCoder

    #1

    UTF8 encoding problem


    I am having a problem preparing a UTF8 string for IPP (internet
    printing protocol) transmission. Converting integers until 639 goes
    well, but beyond this, in case of 640, results in an extra byte(?).
    It shoot be 0x00, 0x00, 0x02 0x80 but I get : 00, 0x00, 0x02 0xc2
    0x80.

    Can somebody give me a hint, please?


    private String Bytes4ToString( int fourbyte)
    {

    Byte[] temp=BitConvert er.GetBytes(fou rbyte);
    char a=(char)temp[3];
    char b=(char)temp[2];
    char c=(char)temp[1];
    char d=(char)temp[0];


    StringBuilder result=new StringBuilder() ;
    result.Append(a .ToString());
    result.Append(b .ToString());
    result.Append(c .ToString());
    result.Append(d .ToString());

    return result.ToString ();

    }

    After this I send a stringbuilder instance "send" including this
    "result" string to a webserver.

    String send=build.ToSt ring();

    UTF8Encoding encoding=new UTF8Encoding();
    Byte[]subdata= encoding.GetByt es(send);

    TIA Gert




  • Jon Skeet [C# MVP]

    #2
    Re: UTF8 encoding problem

    SloppyCoder <tinatuin@hotma il.com> wrote:[color=blue]
    > I am having a problem preparing a UTF8 string for IPP (internet
    > printing protocol) transmission. Converting integers until 639 goes
    > well, but beyond this, in case of 640, results in an extra byte(?).
    > It shoot be 0x00, 0x00, 0x02 0x80 but I get : 00, 0x00, 0x02 0xc2
    > 0x80.
    >
    > Can somebody give me a hint, please?[/color]

    You seem to be confusing character data and binary data. I very much
    doubt that the printing protocol *really* expects its data to come as
    UTF-8 encoded strings which themselves aren't really text but contain
    unicode characters for binary values. I'd be very surprised if numbers
    such as 129 are doing what you expect them to either.

    You're converting into UTF-8 and back at the moment - do you have a
    document describing what is actually expected at the other end? What
    are *you* expecting?

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    Working...