Quoted-Printable

CapReed

Member
Licensed User
Longtime User
Good afternoon,

I found this code in Visual Basic to decode a text quoted-printable encoding. I have problems with the conversion to bytes in hexadecimal, I have seen another example in the forums there to convert an email address that comes in QP to ISO-8859-1, but this part I resist, could you help me to convert this code in BA4 code?

Thank you very much to all!

B4X:
Public Shared Function QuotedPrintableDecode(ByVal text As String) _
As String
  Dim i As Integer
  Dim DecodedString As StringBuilder
  Dim Chars As Char()
  Dim CharsValue As String
  Dim HexValue As Integer
 
  Chars = text.ToCharArray()
  DecodedString = New StringBuilder
 
  For i = 0 To Chars.Length - 1
    If Chars(i) = "=" Then
      CharsValue = Nothing
      HexValue = Nothing
 
      If Chars(i + 1) = "0" Then
        CharsValue = Chars(i + 2)
      Else
        CharsValue = Chars(i + 1) & Chars(i + 2)
      End If
 
      HexValue = Val("&H" & CharsValue)
 
      If CharsValue.ToUpper = Hex(HexValue) Then
        DecodedString.Append(ChrW(HexValue))
        i += 2
      Else
        DecodedString.Append(Chars(i))
      End If
    Else
      DecodedString.Append(Chars(i))
    End If
  Next
 
  Return DecodedString.ToString
End Function
 
Top