none
Determining actual bytes decoded RRS feed

  • Question

  • Hello,

    Is there a way as part of the Decoder class to determine how many bytes were used to actually decode the returned characters? The Convert() method generally returns the number of bytes consumed, including those that don't form a complete sequence. I need the number of bytes that were successfully decoded and translated to characters.

    For example, if I have the sequence {0x24, 0xC2, 0xA2, 0xE2, 0x82}, utf8.Decoder.Convert will give bytesUsed = 5 and charsUsed = 2 (flush is false). The last two bytes are cached (the sixth byte could be 0xAC, so that we would get the Euro symbol). I need to know somehow that only the first 3 bytes were successfully decoded into the 2 characters.

    Knowing this, I can calculate precise offsets when a particular character starts in a stream, so I can start decoding from there.

    Thanks,
    Jason.

    Saturday, August 27, 2011 12:14 PM

Answers

  • Hi Jason,

    Have you tried  Decoder.GetCharCount Method?

    When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes.

    This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Tuesday, September 13, 2011 9:03 AM
    Tuesday, August 30, 2011 7:52 AM

All replies

  • You could Encode the two chars to a byte array and the length of this is the number you are searching for.
    Monday, August 29, 2011 6:28 AM
  • Hi Jason,

    Have you tried  Decoder.GetCharCount Method?

    When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes.

    This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Tuesday, September 13, 2011 9:03 AM
    Tuesday, August 30, 2011 7:52 AM
  •  

    Hi,

     

    Has your issue been resolved? Would you mind letting us know the result of the suggestions?

     

    Now I will mark an answer, you can mark others that you think to be so useful to your issue.

    If you still have any questions about this issue, please feel free to let me know. We will continue to work with you on this issue.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, September 13, 2011 9:03 AM