Reputation: 1665
Can someone please tell me how to do this in C#?
Convert from Quoted Printable to binary, and then use UTF-8 encoding to decode that binary to text.
Here is example of text I need quoted:
"Commentaires: Je suis abonn=C3=A9 =C3=A0 la livraison =C3=A0 domicile depuis longtemps."
Upvotes: 2
Views: 306
Reputation: 66573
OK, so your question is basically two questions in one. First, you need to be able to decode quoted-printable. I’m assuming that you have the encoded text as a string. You’ll have to run through this string with a while-loop, like below. I’ve deliberately left out the part where you turn the two hex characters into a byte; I’m sure you can figure this out for yourself :)
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++;
}
}
At the end of this, output
contains the raw bytes. Now all you need to do is decode it using UTF8:
var outputString = Encoding.UTF8.GetString(output.ToArray());
If you have any questions, please ask in a comment. And remember: don’t copy and use code that you don’t understand :)
Upvotes: 4