转换DART中的扩展ASCII字符
我的Flutter应用程序通过REST接口检索信息,该界面可以包含扩展的ASCII字符,例如e-Eacute 0xe9。如何将其转换为UTF-8(例如0xc3 0xa9),以使其正确显示?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我的Flutter应用程序通过REST接口检索信息,该界面可以包含扩展的ASCII字符,例如e-Eacute 0xe9。如何将其转换为UTF-8(例如0xc3 0xa9),以使其正确显示?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
0xe9对应于ISO-8859/Latin 1编码中的e-atute(é)。 (这是“扩展ASCII”的许多可能的编码之一,尽管我个人将“ Extended ascii”一词与。)
您可以使用 String (它内部存储UTF-16) dart-convert/latin1codec-class.html“ rel =“ nofollow noreferrer”>
latin1codec
。如果您真的想要UTF-8,则可以用0xE9 corresponds to e-acute (é) in the ISO-8859/Latin 1 encoding. (It's one of many possible encodings for "extended ASCII", although personally I associate the term "extended ASCII" with code page 437.)
You can decode it to a Dart
String
(which internally stores UTF-16) usingLatin1Codec
. If you really want UTF-8, you can encode thatString
to UTF-8 afterward withUtf8Codec
.我感到困惑,因为有时数据包含扩展的ASCII字符,有时包含UTF-8字符。当我尝试进行UTF-8解码时,它在扩展的ASCII上进行了baulk。
我通过尝试UTF8解码并在扩展ASCII时捕获错误来修复它,它似乎可以解码此确定。
I was getting confused because sometimes the data contained extended ascii characters and sometimes UTF-8 characters. When I tried doing a UTF-8 decode it baulked at the extended ascii.
I fixed it by trying the utf8 decode and catching the error when it is extended ascii, it seems to decode this OK.
对于混合字符串,您可以使用
Credits https://stackoverflow.com/a/a/a/73512147/7198006
For mixed strings, you can use
credits https://stackoverflow.com/a/73512147/7198006