string substiution char 192-255

J

John

Hi

I have a string which may contain European accented characters - chr(192)
to chr(255).

I need to replace those characters with Å (or whatever the number is)
so that it can be displayed in HTML.

I can use substr($string,$i,1) and walk through it checking for every
character in that range and build a new string.

However, is there a cleaner solution using $x~=s///?

I cannot see it.

Regards
John
 
M

Mirco Wahab

John said:
I have a string which may contain European accented characters - chr(192)
to chr(255).

I need to replace those characters with Å (or whatever the number is)
so that it can be displayed in HTML.

I can use substr($string,$i,1) and walk through it checking for every
character in that range and build a new string.

However, is there a cleaner solution using $x~=s///?

naíve solution:

my $text = '
à Ý X ó Õ Ø € Ç È Ê É ß and à and ò þ and @ and ± and Ç ô õ Å, Ý';

$text =~ s/([\xc0-\xff])/'&#'.ord($1).';'/eg;

just replace every character in range (between 0xC0 and 0xFF)
by a string contructed via /e in substitution.

Regards

Mirco
 
B

Ben Morrow

Quoth "John said:
Hi

I have a string which may contain European accented characters - chr(192)
to chr(255).

I need to replace those characters with Å (or whatever the number is)
so that it can be displayed in HTML.

I can use substr($string,$i,1) and walk through it checking for every
character in that range and build a new string.

However, is there a cleaner solution using $x~=s///?

HTML::Entities (which will also do <, >, & and " for you).

Ben
 
J

John

Mirco Wahab said:
John said:
I have a string which may contain European accented characters -
chr(192) to chr(255).

I need to replace those characters with Å (or whatever the number
is) so that it can be displayed in HTML.

I can use substr($string,$i,1) and walk through it checking for every
character in that range and build a new string.

However, is there a cleaner solution using $x~=s///?

naíve solution:

my $text = '
à Ý X ó Õ Ø € Ç È Ê É ß and à and ò þ and @ and ± and Ç ô õ Å, Ý';

$text =~ s/([\xc0-\xff])/'&#'.ord($1).';'/eg;

just replace every character in range (between 0xC0 and 0xFF)
by a string contructed via /e in substitution.

Regards

Mirco

Many thanks.

I couldn't work out how to link the chr() and the ord().

It's clear now.

Much appreciated.

Regards
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top