Note that there are some explanatory texts on larger screens.

plurals
  1. POText Decoding Problem
    text
    copied!<p>So given this input string:</p> <pre><code>=?ISO-8859-1?Q?TEST=2C_This_Is_A_Test_of_Some_Encoding=AE?= </code></pre> <p>And this function:</p> <pre><code>private string DecodeSubject(string input) { StringBuilder sb = new StringBuilder(); MatchCollection matches = Regex.Matches(inputText.Text, @"=\?(?&lt;encoding&gt;[\S]+)\?.\?(?&lt;data&gt;[\S]+[=]*)\?="); foreach (Match m in matches) { string encoding = m.Groups["encoding"].Value; string data = m.Groups["data"].Value; Encoding enc = Encoding.GetEncoding(encoding.ToLower()); if (enc == Encoding.UTF8) { byte[] d = Convert.FromBase64String(data); sb.Append(Encoding.ASCII.GetString(d)); } else { byte[] bytes = Encoding.Default.GetBytes(data); string decoded = enc.GetString(bytes); sb.Append(decoded); } } return sb.ToString(); } </code></pre> <p>The result is the same as the data extracted from the input string. What am i doing wrong that this text is not getting decoded properly?</p> <p>UPDATE</p> <p>So i have this code for decoding quote-printable:</p> <pre><code>public string DecodeQuotedPrintable(string encoded) { byte[] buffer = new byte[1]; return Regex.Replace(encoded, "=(\r\n?|\n)|=([A-F0-9]{2})", delegate(Match m) { if (byte.TryParse(m.Groups[2].Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out buffer[0])) { return Encoding.ASCII.GetString(buffer); } else { return string.Empty; } }); } </code></pre> <p>And that just leaves the underscores. Do i manually convert those to spaces (Replace("_"," ")), or is there something else i need to do to handle that?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload