Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by tye (Sage)
on Oct 15, 2000 at 09:59 UTC ( [id://36790]=note: print w/replies, xml ) Need Help??


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

$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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://36790]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-20 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found