[Tutor] Re: COnvert a string?

Derrick 'dman' Hudson dman@dman13.dyndns.org
Sun Jul 6 08:19:01 2003


--7JfCtLOvnd9MIVvH
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Jul 06, 2003 at 12:32:59PM +0200, j2 wrote:
| Ok, i am not a _total_ newbie (just almost). But i need to convert a stri=
ng that looks a little something like this
|=20
| =3D?iso-8859-1?Q?Hej=3D2C_tack_f=3DF6r_bra_team_work_p=3DE5_ndc5_i_fredag=
s_efterm?=3D
|     =3D?iso-8859-1?Q?iddag!_/Rolf?=3D
|=20
| into a "plain" textfile (ASCII text only, with spaces between words).=20
| Any hints? I can not figure this out?

First of all, you can't convert that string to plain ASCII unless you
are willing to lose some data.

Second of all, take a look at RFC 2047.  It explains the encoding used
in email headers for non-ASCII data.  The way that works is

 =3D?

Start of the encoded data.

 iso-8859-1

The charset.

 ?

A separator.

 Q

The encoding (quoted-printable or base64).

 ?

A separator.

 Hej=3D2C_tack_f=3DF6r_bra_team_work_p=3DE5_ndc5_i_fredags_efterm

The text.  QP uses the form '=3DXX' for all non-ASCII and various
punctuation characters where XX is the hex value of the character.
(this string becomes "Hej,_tack_f=F6r_bra_team_work_p=E5_ndc5_i_fredags_eft=
erm")

 ?=3D

The end of the encoded data.  Plain ascii data follows, or data
encoded like the previous but (probably, but not necessarily) in a
different charset.


(While a complete understanding isn't wholly necessary, the more you
know the easier it is to do your work.  Now that you know what is
going on here you can upgrade your python version to use the latest
'email' module.)

HTH,
-D

--=20
For society, it's probably a good thing that engineers value function
over appearance.  For example, you wouldn't want engineers to build
nuclear power plants that only _look_ like they would keep all the
radiation inside.
    (Scott Adams - The Dilbert principle)
=20
http://dman13.dyndns.org/~dman/

--7JfCtLOvnd9MIVvH
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj8IE5kACgkQiB6vp1xAVUD/kACfd4L+FHzUjZU4MvvYjprAvaxB
MR4AmwWKePduz1EbgiCsZVcWva0gMexs
=XkLd
-----END PGP SIGNATURE-----

--7JfCtLOvnd9MIVvH--