Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

( #36790=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 tye

$utf16= pack "S*", unpack( "C*", $ascii ), 0; chop( $ascii= pack "C*", unpack "S*", $utf16 );

Where "UTF16" refers to a 16-bit flavor of Unicode that I think is what Microsoft calls UNICODE (and is not very much like what most non-Microsoft references refer to as Unicode which I think is more precisely called UTF8).

Note how the UTF16 string explicitly includes the trailing L'\0' while the ASCII string does not explicitly include the trailing '\0'. This is because Perl strings implicitly include a trailing '\0' tacked on the end but this is not enough to terminate a 16-bit-char string.

     - tye

Comment on Answer: How do I convert a string to Unicode and back (v5.005_03)?
Select or 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 wandering the Monastery: (12)
As of 2014-11-24 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (147 votes), past polls