Home > Archive > PERL Beginners > May 2007 > Convert german umlaut to ascii
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Convert german umlaut to ascii
|
|
| Andreas Moroder 2007-05-21, 4:01 am |
| Hello,
in our application I have to convert all german Umlaute in a string to a
two char combination ä to ae, Ö to OE and so on.
Can anyone please tell me how to do this ?
Thanks
Andreas
| |
| Martin Barth 2007-05-21, 4:01 am |
| On Mon, 21 May 2007 08:41:13 +0200
Andreas Moroder <andreas.moroder@sb-brixen.it> wrote:
> Hello,
>=20
> in our application I have to convert all german Umlaute in a string to a=
=20
> two char combination =C3=A4 to ae, =C3=96 to OE and so on.
>=20
> Can anyone please tell me how to do this ?
>=20
> Thanks
> Andreas
>=20
>=20
for example:
% echo "=C3=A4pfel kl=C3=B6ster =C3=BCbelkeit" | perl -ple 's/=C3=A4/ae/; s=
/=C3=BC/ue/; s/=C3=B6/oe/;'
aepfel kloester uebelkeit
| |
| T Baetzler 2007-05-21, 4:01 am |
| =20
Martin Barth <martin@senfdax.de> suggested:
> On Mon, 21 May 2007 08:41:13 +0200
> Andreas Moroder <andreas.moroder@sb-brixen.it> wrote:
>=20
[color=darkred]
> for example:
>=20
> % echo "=E4pfel kl=F6ster =FCbelkeit" | perl -ple 's/=E4/ae/;=20
> s/=FC/ue/; s/=F6/oe/;'
> aepfel kloester uebelkeit
I would suggest you use a hash to map your conversions:
#!/usr/bin/perl -w
use strict;
my %map =3D ( '=E4' =3D> 'ae', '=C4' =3D> 'Ae',
'=F6' =3D> 'oe', '=D6' =3D> 'Oe',
'=FC' =3D> 'ue', '=DC' =3D> 'Ue',
'=DF' =3D> 'ss' ); # add needed conversions!
my $test =3D "=C4pfel Kl=F6ster =DCbelkeit";
my $in =3D '[' . join( '', keys %map ) . ']';
$test =3D~ s/($in)/$map{$1}/eg;
print "$test\n";
HTH,
Thomas
| |
|
|
| Brad Baxter 2007-05-22, 6:59 pm |
| On May 21, 2:41 am, andreas.moro...@sb-brixen.it (Andreas Moroder)
wrote:
> Hello,
>
> in our application I have to convert all german Umlaute in a string to a
> two char combination =E4 to ae, =D6 to OE and so on.
>
> Can anyone please tell me how to do this ?
>
> Thanks
> Andreas
I would use Text::Unidecode.
http://search.cpan.org/~sburke/Text...xt/Unidecode.pm
It has my favorite motto:
The Text::Unidecode motto is:
It's better than nothing!
--
Brad
| |
| Andreas Moroder 2007-05-23, 4:00 am |
| Thank you to all for your help.
Andreas
| |
|
|
|
|
|