UnicodeToUtf16 (Unicode function): Difference between revisions
Jump to navigation
Jump to search
m (→Examples) |
m (syntax terms, tags and links) |
||
Line 1: | Line 1: | ||
{{Template:Unicode:UnicodeToUtf16 subtitle}} | {{Template:Unicode:UnicodeToUtf16 subtitle}} | ||
<var>UnicodeToUtf16</var> converts a <var>Unicode</var> string to a UTF-16 <var>Longstring</var> byte stream. | |||
==Syntax== | ==Syntax== | ||
{{Template:Unicode:UnicodeToUtf16 syntax}} | {{Template:Unicode:UnicodeToUtf16 syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><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 U+wxyz results in the pair of bytes X'wx' and X'yz', in that order). </td></tr> | ||
<tr><th>unicode</th> | <tr><th>unicode</th> | ||
<td>A <var>Unicode</var> string. </td></tr> | <td>A <var>Unicode</var> string. </td></tr> | ||
<tr><th>InsertBOM | <tr><th>InsertBOM</th> | ||
<td>The optional ( | <td>The optional (<var>[[Methods#Named parameters|Name-Required]]</var>) <var class="term">InsertBOM</var> argument is a <var>[[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== | |||
<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 | |||
</dl> | </dl> | ||
==Usage notes== | ==Usage notes== | ||
<ul> | <ul><li><var>UnicodeToUtf16</var> is available as of <var class="product">[[Sirius Mods|"Sirius Mods"]]</var> Version 7.3.</ul> | ||
<li> | |||
< | |||
</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>. | ||
<p class="code">%u unicode initial('&#x31;':[[U (String function)|U]]) | |||
print %u:unicodeToUtf16:[[StringToHex (String function)|stringToHex]] | |||
<p class="code">%u | print %u:unicodeToUtf16(InsertBOM=True):stringToHex | ||
</p> | </p> | ||
The result is: | The result is: | ||
Line 48: | Line 37: | ||
==See also== | ==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}} | {{Template:Unicode:UnicodeToUtf16 footer}} |
Revision as of 05:47, 25 February 2011
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:
|
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('1':U) print %u:unicodeToUtf16:stringToHex print %u:unicodeToUtf16(InsertBOM=True):stringToHex
The result is:
0031 FEFF0031
See also
- For more information about UTF-16 conversions, see "Unicode: UTF-8 and UTF-16".
- UnicodeToUtf8 converts a Unicode string to UTF-8.
- Utf16ToUnicode converts a UTF-16 Longstring byte stream to Unicode.