Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

FormatException: Invalid UTF-8 byte (at offset 6)

Why do I get an error with this single line of code?

    final pdfString = " (T) 20.5 (–H) 4 (E) ]     % 5-element array of strings, reals, and intege";
    print(utf8.decode(pdfString.codeUnits)); 

why I get

FormatException: Invalid UTF-8 byte (at offset 11)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I copied this string from O’Reilly book.

And independently of the context, how to recover the pdfString if I have its byte representation only ?

>Solution :

As per the documentation for String.codeUnits:

An unmodifiable list of the UTF-16 code units of this string.

(Emphasis added.)

In effect, you are calling utf8.decode() on a UTF-16 string, which is not going to work.

If you provide more context about what you’re actually trying to do, I may be able to offer a suggestion.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading