Convert quoted printable aka PrintableASCII characters to UTF-8

I have had some success with the following function that I wrote a couple of years ago to battle quoted printables on MathGroup:

translateQuotedPrintable[str_String] := 
  StringReplace[str, {"=" ~~ c1:HexadecimalCharacter~~c2:HexadecimalCharacter :> 
    FromCharacterCode[FromDigits[c1 <> c2, 16], "Math1"],"=" ~~ EndOfLine -> ""}]

translateQuotedPrintable["=FCberhaupt"]

"überhaupt"

More about this in my original Stackoverflow posting.

The "Math1" argument of FromCharacterCode could perhaps be dropped. I used it in the context of the MathGroup where a lot of Mathematica symbols got quoted printabled. For normal text, the default translation should be fine.


While I'm not a fan of posting a java based answer when a nice and clean Mathematica solution like Sjoerd's exists, over time I've begun to appreciate Leonid's frequent appeals to learn to "steal code" from Java and use it via JLink. Your comment:

Other languages have their function for this:-(

prompted me to post this answer, to mostly serve as a nudge/reminder that in case you're stuck at a problem and know how to do it in of the several other languages that can be interfaced with Mathematica, then the most productive use of your time would be to quickly whip it up in language X and use it inside Mathematica using the appropriate X-Link application. In that spirit, I'll present the following simple solution using Java/JLink:

Needs["JLink`"]
InstallJava[];
decodeQP[str_] := JavaBlock[
    QPC = JavaNew["org.apache.commons.codec.net.QuotedPrintableCodec"];
    QPC@decode[str, "ISO-8859-1"]
]

Now you can easily use it as decodeQP["=FCberhaupt"], using Sjoerd's example, and it should give you the translated string.

Note that you can't convert directly to "UTF-8" as asked in the question and need to convert it to ISO Latin 1 first (credit goes to Sjoerd for spotting this).