string.html

来自「perl教程」· HTML 代码 · 共 494 行 · 第 1/2 页

HTML
494
字号
sample &quot;祄&quot; is &quot;U+00b5 U+006d&quot; in this encoding.</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="string_operations">String Operations</a></h2>
<p>The following methods are available:</p>
<dl>
<dt><strong><a name="item_as_string">$us-&gt;as_string</a></strong>

<dd>
<p>Converts a <code>Unicode::String</code> to a plain string according to the
setting of stringify_as().  The default <a href="#item_stringify_as"><code>stringify_as()</code></a> encoding is
&quot;utf8&quot;.</p>
</dd>
</li>
<dt><strong><a name="item_as_num">$us-&gt;as_num</a></strong>

<dd>
<p>Converts a <code>Unicode::String</code> to a number.  Currently only the digits
in the range 0x30 .. 0x39 are recognized.  The plan is to eventually
support all Unicode digit characters.</p>
</dd>
</li>
<dt><strong><a name="item_as_bool">$us-&gt;as_bool</a></strong>

<dd>
<p>Converts a <code>Unicode::String</code> to a boolean value.  Only the empty
string is FALSE.  A string consisting of only the character U+0030 is
considered TRUE, even if Perl consider &quot;0&quot; to be FALSE.</p>
</dd>
</li>
<dt><strong><a name="item_repeat">$us-&gt;repeat( $count )</a></strong>

<dd>
<p>Returns a new <code>Unicode::String</code> where the content of $us is repeated
$count times.  This operation is also overloaded as:</p>
</dd>
<dd>
<pre>
  $us x $count</pre>
</dd>
</li>
<dt><strong><a name="item_concat">$us-&gt;concat( $other_string )</a></strong>

<dd>
<p>Concatenates the string $us and the string $other_string.  If
$other_string is not an <code>Unicode::String</code> object, then it is first
passed to the Unicode::String-&gt;new constructor function.  This
operation is also overloaded as:</p>
</dd>
<dd>
<pre>
  $us . $other_string</pre>
</dd>
</li>
<dt><strong><a name="item_append">$us-&gt;append( $other_string )</a></strong>

<dd>
<p>Appends the string $other_string to the value of $us.  If
$other_string is not an <code>Unicode::String</code> object, then it is first
passed to the Unicode::String-&gt;new constructor function.  This
operation is also overloaded as:</p>
</dd>
<dd>
<pre>
  $us .= $other_string</pre>
</dd>
</li>
<dt><strong><a name="item_copy">$us-&gt;copy</a></strong>

<dd>
<p>Returns a copy of the current <code>Unicode::String</code> object.  This
operation is overloaded as the assignment operator.</p>
</dd>
</li>
<dt><strong><a name="item_length">$us-&gt;length</a></strong>

<dd>
<p>Returns the length of the <code>Unicode::String</code>.  Surrogate pairs are
still counted as 2.</p>
</dd>
</li>
<dt><strong><a name="item_byteswap">$us-&gt;byteswap</a></strong>

<dd>
<p>This method will swap the bytes in the internal representation of the
<code>Unicode::String</code> object.</p>
</dd>
<dd>
<p>Unicode reserve the character U+FEFF character as a byte order mark.
This works because the swapped character, U+FFFE, is reserved to not
be valid.  For strings that have the byte order mark as the first
character, we can guaranty to get the byte order right with the
following code:</p>
</dd>
<dd>
<pre>
   <span class="variable">$ustr</span><span class="operator">-&gt;</span><span class="variable">byteswap</span> <span class="keyword">if</span> <span class="variable">$ustr</span><span class="operator">-&gt;</span><span class="keyword">ord</span> <span class="operator">==</span> <span class="number">0xFFFE</span><span class="operator">;</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_unpack">$us-&gt;unpack</a></strong>

<dd>
<p>Returns a list of integers each representing an UCS-2 character code.</p>
</dd>
</li>
<dt><strong><a name="item_pack">$us-&gt;pack( @uchr )</a></strong>

<dd>
<p>Sets the value of $us as a sequence of UCS-2 characters with the
characters codes given as parameter.</p>
</dd>
</li>
<dt><strong><a name="item_ord">$us-&gt;ord</a></strong>

<dd>
<p>Returns the character code of the first character in $us.  The <a href="#item_ord"><code>ord()</code></a>
method deals with surrogate pairs, which gives us a result-range of
0x0 .. 0x10FFFF.  If the $us string is empty, undef is returned.</p>
</dd>
</li>
<dt><strong><a name="item_chr">$us-&gt;chr( $code )</a></strong>

<dd>
<p>Sets the value of $us to be a string containing the character assigned
code $code.  The argument $code must be an integer in the range 0x0
.. 0x10FFFF.  If the code is greater than 0xFFFF then a surrogate pair
created.</p>
</dd>
</li>
<dt><strong><a name="item_name">$us-&gt;name</a></strong>

<dd>
<p>In scalar context returns the official Unicode name of the first
character in $us.  In array context returns the name of all characters
in $us.  Also see <a href="../../lib/Unicode/CharName.html">the Unicode::CharName manpage</a>.</p>
</dd>
</li>
<dt><strong><a name="item_substr">$us-&gt;substr( $offset )</a></strong>

<dt><strong>$us-&gt;substr( $offset, $length )</strong>

<dt><strong>$us-&gt;substr( $offset, $length, $subst )</strong>

<dd>
<p>Returns a sub-string of $us.  Works similar to the builtin <a href="#item_substr"><code>substr()</code></a>
function.</p>
</dd>
</li>
<dt><strong><a name="item_index">$us-&gt;index( $other )</a></strong>

<dt><strong>$us-&gt;index( $other, $pos )</strong>

<dd>
<p>Locates the position of $other within $us, possibly starting the
search at position $pos.</p>
</dd>
</li>
<dt><strong><a name="item_chop">$us-&gt;chop</a></strong>

<dd>
<p>Chops off the last character of $us and returns it (as a
<code>Unicode::String</code> object).</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="functions">FUNCTIONS</a></h1>
<p>The following functions are provided.  None of these are exported by default.</p>
<dl>
<dt><strong><a name="item_byteswap2">byteswap2( $str, ... )</a></strong>

<dd>
<p>This function will swap 2 and 2 bytes in the strings passed as
arguments.  If this function is called in void context,
then it will modify its arguments in-place.  Otherwise, the swapped
strings are returned.</p>
</dd>
</li>
<dt><strong><a name="item_byteswap4">byteswap4( $str, ... )</a></strong>

<dd>
<p>The byteswap4 function works similar to byteswap2, but will reverse
the order of 4 and 4 bytes.</p>
</dd>
</li>
<dt><strong>latin1( $str )</strong>

<dt><strong>utf7( $str )</strong>

<dt><strong>utf8( $str )</strong>

<dt><strong>utf16le( $str )</strong>

<dt><strong>utf16be( $str )</strong>

<dt><strong>utf32le( $str )</strong>

<dt><strong>utf32be( $str )</strong>

<dd>
<p>Constructor functions for the various Unicode encodings.  These return
new <code>Unicode::String</code> objects.  The provided argument should be
encoded correspondingly.</p>
</dd>
</li>
<dt><strong><a name="item_uhex">uhex( $str )</a></strong>

<dd>
<p>Constructs a new <code>Unicode::String</code> object from a string of hex
values.  See <a href="#item_hex"><code>hex()</code></a> method above for description of the format.</p>
</dd>
</li>
<dt><strong><a name="item_uchar">uchar( $num )</a></strong>

<dd>
<p>Constructs a new one character <code>Unicode::String</code> object from a
Unicode character code.  This works similar to perl's builtin <a href="#item_chr"><code>chr()</code></a>
function.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="../../lib/Unicode/CharName.html">the Unicode::CharName manpage</a>,
<a href="../../Unicode/Map8.html">the Unicode::Map8 manpage</a></p>
<p><a href="http://www.unicode.org/">http://www.unicode.org/</a></p>
<p><a href="../../lib/Pod/perlunicode.html">the perlunicode manpage</a></p>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>Copyright 1997-2000,2005 Gisle Aas.</p>
<p>This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.</p>

</body>

</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?