CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Substitute accented characters in string

 



kepler
Novice

Oct 21, 2015, 1:03 AM

Post #1 of 4 (1499 views)
Substitute accented characters in string Can't Post

Good morning,

I'm looking for a script that allows to transform a string with accented characters and others special characters (for instance , , , , , etc... to i,e,a,c,o, etc...).

Does Text::Unidecode does that, like:


Code
use utf8; 
use Text::Unidecode;

$str = "hell ";
$str2 = unidecode($str);

#will $str2 equal to "hello i c o"???


?

Kind regards,

Kepler


Laurent_R
Veteran / Moderator

Oct 21, 2015, 5:58 AM

Post #2 of 4 (1491 views)
Re: [kepler] Substitute accented characters in string [In reply to] Can't Post

Yes, that's what Text::Unidecode is supposed to do: a quick (and not so clean) way of rendering non ASCII characters (or extended ASCII characters) into simple 128-bit ASCII characters. Good enough for simple transliteration of, say, , , , into a, u, u, c, or something like that, but don't expect accurate transliteration for all cases and languages.

But what was your question, really? Did you try it?


kepler
Novice

Oct 21, 2015, 3:03 PM

Post #3 of 4 (1475 views)
Re: [Laurent_R] Substitute accented characters in string [In reply to] Can't Post

Hi,

Yes, I've tryed - but unfortunatly I don't have that module installed... :(

So, I've used this code:


Code
#!/usr/bin/perl 
use warnings;
use strict;
use Unicode::Normalize;
use Encode;

my $string = "+lsctz}";
print "$string\n";
$string = decode("ISO-8859-1", $string);
$string = NFD($string);
$string =~ s/\pM//og;
print "$string\n";
exit;


Here's the output:


Code
+lsctz} 
+lsctzuiaec} #it worked :)


My doubt now, is regarding the iso code I must use (which will work with all the cases - this seems to work)... Is there a plain ascii iso code?

Cheers,

Kepler


Laurent_R
Veteran / Moderator

Oct 22, 2015, 1:34 AM

Post #4 of 4 (1459 views)
Re: [kepler] Substitute accented characters in string [In reply to] Can't Post


In Reply To
Yes, I've tryed - but unfortunatly I don't have that module installed... :(


Why don't you install it? If I am not wrong, it is a pure-Perl no-dependency module, so it should be easy enough for you to install on just about any platform.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives