Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Answer: How do I convert a string to Unicode and back (v5.005_03)?

( #102850=categorized answer: print w/ replies, xml ) Need Help??

Q&A > strings > How do I convert a string to Unicode and back (v5.005_03)? contributed by mirod

If you have the iconv library on your system then the easiest way is to use Text::Iconv:

use Text::Iconv; my $enc= 'latin1'; # or any other encoding supported by iconv, iconv - +-list gives the list my $enc2utf = new Text::Iconv( $enc, 'utf8') or die "Can't create enc2utf converter"; my $utf2enc= new Text::Iconv( 'utf8', $enc) or die "Can't create utf2enc converter"; # then you can convert strings like this: my $utf8_string= $enc2utf->convert( $enc_string); my $enc_string= $utf2enc->convert( $utf8_string);

This works with every character encoding supported by iconv, be it 1-byte or multi-byte.

You can also have a look at Converting character encodings for a discussion on character conversion.

Comment on Answer: How do I convert a string to Unicode and back (v5.005_03)?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (15)
As of 2014-07-30 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls