Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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)? - Answer 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 making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2016-07-01 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (410 votes). Check out past polls.