Unicode::String - String of Unicode characters (UTF-16BE)
| Use Case | Command | Description |
|---|---|---|
| Create UTF-8 string | utf8("string") | Construct a Unicode::String from UTF-8 encoded bytes |
| Create Latin-1 string | latin1("string") | Construct from ISO-8859-1 bytes |
| Create UTF-16BE string | utf16be("\0s\0t\0r\0i\0n\0g") | Construct from big-endian UTF-16 |
| Convert to UTF-8 | $u->utf8 | Return UTF-8 encoded version |
| Convert to UTF-16LE | $u->utf16le | Return little-endian UTF-16 |
| Convert to UTF-32BE | $u->utf32be | Return big-endian UTF-32 |
| String length | $u->length | Number of Unicode characters |
| Concatenate strings | $u . $other | Overloaded concatenation operator |
| Repeat string | $u x $count | Overloaded repetition operator |
| Get character code | $u->ord | Ordinal of first character (supports surrogates) |
use Unicode::String qw(utf8 latin1 utf16be);
$u = utf8("string");
$u = latin1("string");
$u = utf16be("\0s\0t\0r\0i\0n\0g");
print $u->utf32be; # 4 byte characters
print $u->utf16le; # 2 byte characters + surrogates
print $u->utf8; # 1-4 byte characters
A "Unicode::String" object represents a sequence of Unicode characters. Methods are provided to convert between various external formats (encodings) and "Unicode::String" objects, and methods are provided for common string manipulations.
The functions utf32be(), utf32le(), utf16be(), utf16le(), utf8(), utf7(), latin1(), uhex(), uchr() can be imported from the "Unicode::String" module and will work as constructors initializing strings of the corresponding encoding.
The "Unicode::String" objects overload various operators, which means that they in most cases can be treated like plain strings.
Internally a "Unicode::String" object is represented by a string of 2 byte numbers in network byte order (big-endian). This representation is not visible by the API provided, but it might be useful to know in order to predict the efficiency of the provided methods.
The following class methods are available:
Unicode::String->stringify_asUnicode::String->stringify_as( $enc )$us = Unicode::String->new$us = Unicode::String->new( $initial_value )These methods get or set the value of the "Unicode::String" object by passing strings in the corresponding encoding. If a new value is passed as argument it will set the value of the "Unicode::String", and the previous value is returned. If no argument is passed then the current value is returned.
To illustrate the encodings we show how the 2 character sample string of "ยตm" (micro meter) is encoded for each one.
$us->utf32be$us->utf32be( $newval )$us->utf32le$us->utf32le( $newval )$us->utf16be$us->utf16be( $newval )$us->utf16le$us->utf16le( $newval )$us->utf8$us->utf8( $newval )$us->utf7$us->utf7( $newval )$us->latin1$us->latin1( $newval )$us->hex$us->hex( $newval )The following methods are available:
$us->as_string$us->as_num$us->as_bool$us->repeat( $count )$us x $count$us->concat( $other_string )$us . $other_string$us->append( $other_string )$us .= $other_string$us->copy$us->length$us->byteswap$ustr->byteswap if $ustr->ord == 0xFFFE$us->unpack$us->pack( @uchr )$us->ord$us->chr( $code )$us->name$us->substr( $offset )$us->substr( $offset, $length )$us->substr( $offset, $length, $subst )$us->index( $other )$us->index( $other, $pos )$us->chopThe following functions are provided. None of these are exported by default.
byteswap2( $str, ... )byteswap4( $str, ... )latin1( $str )utf7( $str )utf8( $str )utf16le( $str )utf16be( $str )utf32le( $str )utf32be( $str )uhex( $str )uchar( $num )Copyright 1997-2000,2005 Gisle Aas
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-08 03:30 @2600:1f28:365:80b0:6814:a048:8015:f4ec
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format