VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Quoted-PrintableEncode and Decode

by AndrComm (4 Submissions)
Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

Very fast function to encode or decode Quoted-Printable.
VB6 only, but you can make it work with other versions, with a 3rd party replace function.

Inputs
Just pass it the string to be encoded, or to be decoded.
Code Returns
The encoded, or decoded string.

Rate Quoted-PrintableEncode and Decode

Public Function DecodeQP(ByRef StrToDecode As String) As String
Dim sTemp As String
Dim i As Integer
sTemp = StrToDecode
For i = 255 To 127 Step -1
  If InStr(1, sTemp, "=" & Hex$(i)) <> 0 Then sTemp = Replace(sTemp, "=" & Hex$(i), Chr$(i))
Next
  If InStr(1, sTemp, "=" & Hex$(61)) <> 0 Then sTemp = Replace(sTemp, "=" & Hex$(61), Chr$(255) & Chr$(254))
For i = 32 To 10 Step -1
  If InStr(1, sTemp, "=" & Hex$(i)) <> 0 Then sTemp = Replace(sTemp, "=" & Hex$(i), Chr$(i))
Next
For i = 9 To 0 Step -1
  If InStr(1, sTemp, "=" & "0" & Hex$(i)) <> 0 Then sTemp = Replace(sTemp, "=" & Hex$(i), Chr$(i))
Next
sTemp = Replace(sTemp, "=", "")
sTemp = Replace(sTemp, Chr$(255) & Chr$(254), "=")
DecodeQP = sTemp
End Function
Public Function EncodeQP(ByRef StrToEncode As String) As String
Dim sTemp As String
Dim i As Integer
sTemp = StrToEncode
For i = 255 To 127 Step -1
  If InStr(1, sTemp, Chr$(i)) <> 0 Then sTemp = Replace(sTemp, Chr$(i), "=" & Hex$(i))
Next
  If InStr(1, sTemp, Chr$(61)) <> 0 Then sTemp = Replace(sTemp, Chr$(61), "=" & Hex$(61))
For i = 32 To 10 Step -1
  If InStr(1, sTemp, Chr$(i)) <> 0 Then sTemp = Replace(sTemp, Chr$(i), "=" & Hex$(i))
Next
For i = 9 To 0 Step -1
  If InStr(1, sTemp, Chr$(i)) <> 0 Then sTemp = Replace(sTemp, Chr$(i), "=" & "0" & Hex$(i))
Next
EncodeQP = sTemp
End Function

Download this snippet    Add to My Saved Code

Quoted-PrintableEncode and Decode Comments

No comments have been posted about Quoted-PrintableEncode and Decode. Why not be the first to post a comment about Quoted-PrintableEncode and Decode.

Post your comment

Subject:
Message:
0/1000 characters