2012-01-07 178 views
0

我有一點問題,這裏是調試輸出VB.NET轉換的Unicode 8(UTF8)到普通美國ASCII

"?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ƒ

也許蠻力攻擊,直到?u=83比賽真的我想閱讀一個Unicode-32(巴西郵件格式的文本(POP3)。現在我認爲=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 

編輯: 我在固定功能(如果它真的會導致問題,我永遠也不會知道?)

公共共享功能DecodeQuotedPrintable(BYVAL消息作爲字符串,可選BYVAL快速清潔作爲嘗試布爾=假)作爲字符串 「設置StringBuilder對象剝去任何行接續的標籤 昏暗消息作爲新的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 

端功能

回答

1

「ƒ」 由= 83在Windows-1252字符集引用Printable編碼表示。

+0

很酷所以我修好了,問題是它讀取URL參數作爲編碼 – SSpoke 2012-01-08 07:01:55