英文:
FormatException: Invalid UTF-8 byte (at offset 6)
问题
为什么我在这一行代码中出现错误?
final pdfString = "" (T) 20.5 (–H) 4 (E) ] % 5-element array of strings, reals, and intege"";
print(utf8.decode(pdfString.codeUnits));
为什么我会得到以下错误信息?
FormatException: Invalid UTF-8 byte (at offset 11)
我是从 O'Reilly 的书中复制这个字符串的。
无论上下文如何,如果我只有它的字节表示,如何恢复 pdfString
?
英文:
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)
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 ?
答案1
得分: 0
根据String.codeUnits的文档:
一个字符串的UTF-16代码单元的不可修改列表。
(已强调。)
实际上,您正在对一个UTF-16字符串调用utf8.decode()
,这是行不通的。
如果您提供关于您实际尝试做什么的更多上下文,我可能可以提供建议。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论