dongshan1811 2017-11-15 04:30
浏览 606
已采纳

如何在Golang中获取带引号的可打印字符串

How to get a quoted printable string created according to » RFC2045, section 6.7. in golang

PHP equivalent is "quoted_printable_encode ( string $str )"

  • 写回答

1条回答 默认 最新

  • dongyuan4790 2017-11-15 06:45
    关注

    Use the standard quotedprintable package to encode the string:

    ...
    
    import (
        "bytes"
        "mime/quotedprintable"
        "github.com/pkg/errors"
    )
    
    ...
    
    func toQuotedPrintable(s string) (string, error) {
        var ac bytes.Buffer
        w := quotedprintable.NewWriter(&ac)
        _, err := w.Write([]byte(s))
        if err != nil {
            return "", errors.Wrap(err, "write")
        }
        err = w.Close()
        if err != nil {
            return "", errors.Wrap(err, "close")
        }
        return ac.String(), nil
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?