Wiki Home

Quoted Printable Encoder


Namespace: WIN_COM_API
"Quoted-Printable" is a MIME standard for using non-english character sets.

I haven't fully digested the RFC's describing it: RFC2045 and RFC1522, but this is a quick and dirty way to encode a string in a given charset:

* Usage:
lcEncoded = QEncode( strInput, strCharSetDescription )

lcEncode = QEncode( 'Nšidiskiri ise tehtus', 'windows-1257' )
* lcEncode  now = "=?windows-1257?Q?N=E4idiskiri=20ise=20tehtus?="
*   or this: "=?windows-1257?Q?N=E4idiskiri_ise_tehtus?=" with the "space" encoding enabled.

FUNCTION QEncode( tcIn, tcCharSet )
LOCAL lnI, lcOut, lcI
lcOut = '=?'+tcCharSet+'?Q?'

for lnI = 1 to len(tcIn)
  lcI = substr(tcIn,lnI,1)
  do case
    case asc(lcI)=32
      lcOut = lcOut + '_'
    case asc(lcI)<32 or asc(lcI)>126
      lcOut = lcOut + '=' + right(transform(asc(lcI),[email protected]'),2)
    otherwise
      lcOut = lcOut + lcI
  ENDCASE
ENDFOR
lcOut = lcOut + '?='
RETURN lcOut
ENDFUNC

Contributors: wgcs
Category Code Samples Category Web
( Topic last updated: 2004.07.29 04:18:59 PM )