UnicodeToUtf16 (Unicode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
mNo edit summary
 
(17 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Template:Unicode:UnicodeToUtf16 subtitle}}
{{Template:Unicode:UnicodeToUtf16 subtitle}}
[[Category:Unicode methods|UnicodeToUtf16 function]]
<var>UnicodeToUtf16</var> converts a <var>Unicode</var> string to a UTF-16 <var>Longstring</var> byte stream.
[[Category:Intrinsic methods]]
<!--DPL?? Category:<var>Unicode</var> methods|<var>UnicodeToUtf16</var> function: <var>Unicode</var> string converted to UTF-16 byte stream-->
<!--DPL?? Category:Intrinsic methods|<var>UnicodeToUtf16</var> (<var>Unicode</var> function): <var>Unicode</var> string converted to UTF-16 byte stream-->
<!--DPL?? Category:<var>System</var> methods|<var>UnicodeToUtf16</var> (<var>Unicode</var> function): <var>Unicode</var> string converted to UTF-16 byte stream-->


This function converts a <var>Unicode</var> string to a UTF-16
<var>Longstring</var> byte stream.
The <var>UnicodeToUtf16</var> function is available as of version 7.3 of the <var class=product>Sirius Mods</var>.
==Syntax==
==Syntax==
{{Template:Unicode:UnicodeToUtf16 syntax}}
{{Template:Unicode:UnicodeToUtf16 syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th><i>%utf16Stream</i></th>
<tr><th>%string</th>
<td>A <var>String</var> or <var>Longstring</var> variable to receive the method object string translated to a UTF-16 Big-Endian byte stream (that is, any <var>Unicode</var> point U+wxyz results in the pair of bytes X'wx' and X'yz', in that order). </td></tr>
<td>A <var>String</var> or <var>Longstring</var> variable to receive the method object string translated to a UTF-16 Big-Endian byte stream (that is, any <var>Unicode</var> point <code>U+wxyz</code> results in the pair of bytes <code>X'wx'</code> and <code>X'yz'</code>, in that order). </td></tr>
<tr><th><i>unicode</i></th>
 
<tr><th>unicode</th>
<td>A <var>Unicode</var> string. </td></tr>
<td>A <var>Unicode</var> string. </td></tr>
<tr><th><b>InsertBOM=</b><i>bool</i></th>
 
<td>The optional (name required) InsertBOM argument is a Boolean: <ul> <li>If its value is <tt>True</tt>, the "Byte Order Mark" (U+FEFF) is inserted at the start of the output stream. <li>If its value is <tt>False</tt>, the default, no Byte Order Mark is inserted. </ul></td></tr>
<tr><th><var>InsertBOM</var></th>
<td>The optional, [[Notation conventions for methods#Named parameters|name required]], <var>InsertBOM</var> argument is a <var>[[Enumerations#Using Boolean enumerations|Boolean]]</var>:  
<ul>  
<li>If its value is <code>True</code>, the "Byte Order Mark" (U+FEFF) is inserted at the start of the output stream.  
<li>If its value is <code>False</code>, the default, no Byte Order Mark is inserted.  
</ul></td></tr>
</table>
</table>
===Exceptions===


This function can throw the following exception:
==Exceptions==
<var>UnicodeToUtf16</var> can throw the following exception:
<dl>
<dl>
<dt><var>CharacterTranslationException</var>
<dt><var>[[CharacterTranslationException class|CharacterTranslationException]]</var>
<dd>If the method encounters a translation problem,
<dd>If the method encounters a translation problem, properties of the exception object may indicate the location and type of problem.
properties of the exception object may indicate the location and type of problem.
See [[CharacterTranslationException exception class]].
</dl>
</dl>
==Usage notes==
==Usage notes==
<ul>
<ul>
<li>For more information about UTF-16 conversions, see [[Unicode#UTF-8 and UTF-16]].
<li><var>UnicodeToUtf16</var> is available as of <var class="product">Sirius Mods</var> Version 7.3.
<li>The [[UnicodeToUtf8 (Unicode function)|UnicodeToUtf8]] method
converts a <var>Unicode</var> string to UTF-8.
<li>The [[Utf16ToUnicode (String function)|Utf16ToUnicode]] method
converts a UTF-16 <var>Longstring</var> byte stream to <var>Unicode</var>.
</ul>
</ul>
==Examples==
==Examples==
The following fragment shows a successful call of <var>UnicodeToUtf16</var>.
The following fragment shows a successful call of <var>UnicodeToUtf16</var>.
The [[U (String function)|U constant function]] and [[StringToHex (String function)|StringToHex]] function
<p class="code">%u unicode initial('&amp;#x31;':[[U (String function)|U]])
are used in the example.
print %u:unicodeToUtf16:[[StringToHex (String function)|stringToHex]]
<p class="code">%u <var>Unicode</var> Initial('&amp;#x31;':U)
print %u:unicodeToUtf16(InsertBOM=True):stringToHex
Print %u:<var>UnicodeToUtf16</var>:<var>String</var>ToHex
Print %u:<var>UnicodeToUtf16</var>(InsertBOM=True):<var>String</var>ToHex
</p>
</p>
The result is:
The result is:
Line 51: Line 43:
FEFF0031
FEFF0031
</p>
</p>
==See also==
<ul>
<li>For more information about UTF-16 conversions, see [[Unicode#UTF-8 and UTF-16|"Unicode: UTF-8 and UTF-16"]].
<li><var>[[UnicodeToUtf8 (Unicode function)|UnicodeToUtf8]]</var> converts a <var>Unicode</var> string to UTF-8.
<li><var>[[Utf16ToUnicode (String function)|Utf16ToUnicode]]</var> converts a UTF-16 <var>Longstring</var> byte stream to <var>Unicode</var>.
</ul>
{{Template:Unicode:UnicodeToUtf16 footer}}

Latest revision as of 20:07, 6 November 2012

Translate to UTF-16 (Unicode class)

UnicodeToUtf16 converts a Unicode string to a UTF-16 Longstring byte stream.

Syntax

%string = unicode:UnicodeToUtf16[( [InsertBOM= boolean])]

Syntax terms

%string A String or Longstring variable to receive the method object string translated to a UTF-16 Big-Endian byte stream (that is, any Unicode point U+wxyz results in the pair of bytes X'wx' and X'yz', in that order).
unicode A Unicode string.
InsertBOM The optional, name required, InsertBOM argument is a Boolean:
  • If its value is True, the "Byte Order Mark" (U+FEFF) is inserted at the start of the output stream.
  • If its value is False, the default, no Byte Order Mark is inserted.

Exceptions

UnicodeToUtf16 can throw the following exception:

CharacterTranslationException
If the method encounters a translation problem, properties of the exception object may indicate the location and type of problem.

Usage notes

  • UnicodeToUtf16 is available as of Sirius Mods Version 7.3.

Examples

The following fragment shows a successful call of UnicodeToUtf16.

%u unicode initial('&#x31;':U) print %u:unicodeToUtf16:stringToHex print %u:unicodeToUtf16(InsertBOM=True):stringToHex

The result is:

0031 FEFF0031

See also