有人可以告诉我如何在 C# 中执行此操作吗?
从 Quoted Printable 转换为二进制,然后使用 UTF-8 编码将该二进制解码为文本。
这是我需要引用的文本示例:
“评论:Je suis abonn=C3=A9 =C3=A0 la livraison =C3=A0 domicile depuis longtemps。”
最佳答案
好的,所以你的问题基本上是两个问题合二为一。首先,您需要能够解码quoted-printable。我假设您将编码文本作为字符串。您必须使用 while 循环遍历该字符串,如下所示。我故意省略了将两个十六进制字符转换为字节的部分;我相信您可以自己解决这个问题:)
var i = 0;
var output = new List<byte>();
while (i < input.Length)
{
if (input[i] == '=' && input[i+1] == '\r' && input[i+2] == '\n')
{
// skip this
i += 3;
}
else if (input[i] == '=')
{
byte b = (construct the byte from the characters input[i+1] and input[i+2]);
output.Add(b);
i += 3;
}
else
{
output.Add((byte)input[i]);
i++;
}
}
最后,输出
包含原始字节。现在您需要做的就是使用 UTF8 对其进行解码:
var outputString = Encoding.UTF8.GetString(output.ToArray());
如有任何疑问,请在评论中提问。请记住:不要复制和使用您不理解的代码:)
关于c# - 转换问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3388934/