与Uri.EscapeUriString()关于重音符号问题重音、符号、问题、Uri

2023-09-07 16:38:43 作者:眉眼如初

如果我试图把一个URL与重音字符的功能,如Percepção时,输出Percep%C3%A7%C3%A 3 O,而无法正常工作。然而,Percep%E7%e3o做工作的方式是应该的。

If I try to put a URL in the function with accented characters, like "Percepção", it outputs "Percep%C3%A7%C3%A3o", which doesn't work correctly. However, "Percep%e7%e3o" does work the way it should.

String Result = Uri.EscapeUriString("Percepção");

在此先感谢。

Thanks in advance.

推荐答案

我只是第一次编码原始字符串为ASCII字节,然后编码回UTF8修复了这个问题。

I just fixed this issue by encoding the original string to ASCII bytes first, and then encoding it back to UTF8.

String Result = Uri.EscapeUriString(Encoding.UTF8.GetString(Encoding.ASCII.GetBytes("Percepção")));

由于二进制codeR一些更多的细节。

Thanks to binarycoder for some more details.