decoding quoted-printables

前端 未结 6 1503
伪装坚强ぢ
伪装坚强ぢ 2020-12-20 16:40

I am looking for a way to decode quoted-printables.

The quoted-printables are for arabic characters and look like this:

=D8=B3=D8=B9=D8=A7=D8=

6条回答
  •  [愿得一人]
    2020-12-20 17:37

    In my case I was coming from EML... bensnider's answer worked great... quoted-printable (at least in EML) uses an = sign followed by \r\n to signify a line wrapping, so this was the code needed to cleanly translate:

    (Made as a category cause I loves dem)

    @interface NSString (QuotedPrintable)
    - (NSString *)quotedPrintableDecode;
    @end
    
    @implementation NSString (QuotedPrintable)
    - (NSString *)quotedPrintableDecode
    {
        NSString *decodedString = [self stringByReplacingOccurrencesOfString:@"=\r\n" withString:@""]; // Ditch the line wrap indicators
        decodedString = [decodedString stringByReplacingOccurrencesOfString:@"=" withString:@"%"]; // Change the ='s to %'s
        decodedString = [decodedString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; // Replace the escaped strings.
        return decodedString;
    }
    @end
    

    Which worked great for decoding my EML / UTF-8 objects!

提交回复
热议问题