Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Charset, encoding
Message
From
29/06/2011 12:08:01
 
General information
Forum:
Visual FoxPro
Category:
Internet applications
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Vista
Application:
Desktop
Miscellaneous
Thread ID:
01516651
Message ID:
01516713
Views:
30
We came up with theses functions:
clear

? StringQuotedPrintableEncode('La Chèvre du Château', 'iso-8859-1')
? StringQuotedPrintableDecode('La Ch=E8vre du Ch=E2teau', 'iso-8859-1')

*-----
function StringQuotedPrintableEncode
	*
	*/CC/ Encode a string to QuotedPrintable and a Charset
	*
	lparameters lcSourceString, lcCharset

	local lcEncodedString, loMessage, loStream
	lcEncodedString = ''

	if not empty(lcSourceString) and not empty(lcCharset)

		loMessage = createobject('CDO.Message')
		loMessage.BodyPart.ContentTransferEncoding = 'quoted-printable'
		loStream = loMessage.BodyPart.GetDecodedContentStream()

		loStream.Charset = lcCharset
		loStream.WriteText(lcSourceString)
		loStream.Flush

		loStream = loMessage.BodyPart.GetEncodedContentStream()
		lcEncodedString = loStream.ReadText()

	endif

return lcEncodedString
*-----

*-----
function StringQuotedPrintableDecode
	*
	*/CC/ Decode to 1252 a quoted printable string
	*
	lparameters lcSourceString, lcCharset

	local lcDecodedString, loMessage, loStream
	lcDecodedString = ''

	if not empty(lcSourceString) and not empty(lcCharset)

		loMessage = createobject('CDO.Message')
		loMessage.BodyPart.contenttransferencoding = 'quoted-printable'
		loStream = loMessage.BodyPart.GetEncodedContentStream()

		loStream.Charset = 'windows-1252'
		loStream.WriteText(lcSourceString)
		loStream.Flush

		loStream = loMessage.BodyPart.GetDecodedContentStream()
		loStream.Charset = lcCharset
		lcDecodedString = loStream.ReadText

	endif

return lcDecodedString
*-----
>>Hi all,
>>
>>We receive VCF files that include special Charset encoding:
>>
>>
>>FN;CHARSET=ISO-8859-1;ENCODING=QUOTED-PRINTABLE:G=E9rard La Boutique 
>>
>>
>>We want to convert this string to :
>>
>>
>>FN;Gérard La Boutique
>>
>>
>>How to decode this string according to this Charset ?
>
>
>lcFileContents=filetostr(lcFileNameWithPath)
>lcFileContents=strtran(lcFileContents,[FN;CHARSET=ISO-8859-1;ENCODING=QUOTED-PRINTABLE:],[FN;])
>** specific unescaping here
>lcFileContents=strtran(lcFileContents,[=E9],[é])
>strtofile(lcFileContents,lcFileNameWithPath)
>
Gensoft Sàrl
Christian Carron
Previous
Reply
Map
View

Click here to load this message in the networking platform