Flutter/Dart-字符串,带有UTF8十六进制代码到Latin1



我在这里遇到了一个问题,我以前在Stackoverflow或任何API上都找不到任何帮助。。。问题是,我得到了这个字符串:

"A_Escadaria--Fernand_L%C3%A9ger.jpg"

这是我从AssetManifest.json 中得到的一个文件的名称

%C3%A9是相当于字母"的UTF8十六进制é";,这是拉丁1(我想(。

我需要将这些字符转换为它们真正的等价值(在这种情况下是"é"(,但我不能。。。我已经使用了latin1.encode/decodeutf8.encode/decodeString.fromCharCodes。。。。任何组合都没有结果。

有人能告诉我如何解决这个问题,并将UTF8十六进制字符串转换为实际字符吗??

根据@rob napier的评论,我使用了错误的函数来进行转换,因为这些十六进制UTF-8代码的术语被称为";百分比编码";。

因此,正确的方法是:

String correctString = Uri.decodeComponent(stringWithPercentEncodingChars);

更多信息可以在@rob napier发布的网站上找到:

https://api.flutter.dev/flutter/dart-core/Uri/decodeComponent.html

最新更新