VB.NET 将 Unicode 8 (UTF8) 转换为常规美国 ASCII

问题描述 投票:0回答:1

我这里有问题是调试输出

"?uƒn74tn5187r&key=6e6e0936c4e6c48be56a72eba8964df0"

应该是

"?u=83n74tn5187r&key=6e6e0936c4e6c48be56a72eba8964df0"

我尝试过另一个类似问题的解决方案,但失败了。

Dim uni As Byte() = Encoding.GetEncoding(437).GetBytes("?uƒn74tn5187r&key=6e6e0936c4e6c48be56a72eba8964df0")
Dim Ascii As String = Encoding.ASCII.GetString(uni)

ASCII =

"?u?n74tn5187r&key=6e6e0936c4e6c48be56a72eba8964df0"

我猜我必须猜437..也许对所有数字进行暴力攻击,直到来自

?u=83
?uƒ

比赛

我真的正在尝试从电子邮件(POP3)中读取 Unicode-32(巴西格式的文本)。现在我想起来了

=83
在这里使用这个函数可能会搞砸。

但是如果没有此功能,POP3 电子邮件的正文将包含可能无用的内容,例如 urlencode() 的变体,但是..而不是

%20
,它使用
=20

我想知道如何解决这个问题。

 Public Shared Function DecodeQuotedPrintable(ByVal Message As String, Optional ByVal QuickClean As Boolean = False) As String
        'set up StringBuilder object with data stripped of any line continuation tags
        Dim Msg As New StringBuilder(Message.Replace("=" & vbCrLf, vbNullString))

        If QuickClean Then                                                  'perform a quick clean (clean up common basics)
            Return Msg.Replace("=" & vbCrLf, vbNullString).Replace("=0D", vbCr).Replace("=0A", _
                                   vbLf).Replace("=20", " ").Replace("=3D", "=").ToString
        Else                                                                'perform total cleaning
            'store 2-character hex values that require a leading "0"
            Dim HxData As String = "X0102030405060708090A0B0C0D0E0F"
            For Idx As Integer = 1 To &HF                                   'initially process codes 1-15, which require a leading zero
                Msg.Replace("=" & Mid(HxData, Idx << 1, 2), Chr(Idx))       'replace hex data with single character code (SHIFT is faster)
            Next
            For idx As Integer = &H10 To &HFF                               'process the whole 8-bit extended ASCII gambit
                Msg.Replace("=" & Hex(idx), Chr(idx))                       'replace hex data with single character code
            Next
            Return Msg.ToString                                             'return result string
        End If
    End Function

编辑: 我尝试修复该功能(如果它真的导致问题?我永远不会知道)

Public Shared Function DecodeQuotedPrintable(ByVal Message As String, Optional ByVal QuickClean As Boolean = False) As String
    'set up StringBuilder object with data stripped of any line continuation tags
    Dim Msg As New StringBuilder(Message.Replace("=" & vbCrLf, vbNullString))

    If QuickClean Then                                                  'perform a quick clean (clean up common basics)
        Return Msg.Replace("=" & vbCrLf, vbNullString).Replace("=0D", vbCr).Replace("=0A",
                           vbLf).Replace("=20", " ").Replace("=3D", "=").ToString
    Else                                                                'perform total cleaning
        'store 2-character hex values that require a leading "0"

        Msg.Replace("=" & vbCrLf, vbNullString).Replace("=0D", vbCr).Replace("=0A",
                           vbLf).Replace("=20", " ").Replace("=3D", "%$#@[EQUALS]@#$%").ToString()

        Dim HxData As String = "X0102030405060708090A0B0C0D0E0F"
        For Idx As Integer = 1 To &HF                                   'initially process codes 1-15, which require a leading zero
            Msg.Replace("=" & Mid(HxData, Idx << 1, 2), Chr(Idx))       'replace hex data with single character code (SHIFT is faster)
        Next
        For idx As Integer = &H10 To &HFF                               'process the whole 8-bit extended ASCII gambit
            Msg.Replace("=" & Hex(idx), Chr(idx))                       'replace hex data with single character code
        Next

        Msg.Replace("%$#@[EQUALS]@#$%", "=")

        Return Msg.ToString                                             'return result string
    End If
End Function
vb.net utf-8 ascii pop3 quoted-printable
1个回答
1
投票

“f”在 Windows-1252 字符集中的 Quoted Printable 编码中由 =83 表示。

© www.soinside.com 2019 - 2024. All rights reserved.