UnicodeToEbcdic (Unicode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
<span style="font-size:120%; color:black"><b>String converted from Unicode to EBCDIC</b></span>
{{Template:Unicode:UnicodeToEbcdic subtitle}}
[[Category:Intrinsic Unicode methods|UnicodeToEbcdic function]]
[[Category:Intrinsic Unicode methods|UnicodeToEbcdic function]]
[[Category:Intrinsic methods]]
[[Category:Intrinsic methods]]
Line 12: Line 12:


The UnicodeToEbcdic function is available as of version 7.3 of the ''Sirius Mods''.
The UnicodeToEbcdic function is available as of version 7.3 of the ''Sirius Mods''.
===Syntax===
==Syntax==
  %ebcdic = unicode:UnicodeToEbcdic([CharacterEncode=bool])
{{Template:Unicode:UnicodeToEbcdic syntax}}
====Syntax Terms====
===Syntax terms===
<dl>
<dl>
<dt><i>%ebcdic</i>
<dt><i>%ebcdic</i>
Line 31: Line 31:


For example, the eight characters <tt>&amp;#x201C;</tt> replace the Unicode
For example, the eight characters <tt>&amp;#x201C;</tt> replace the Unicode
&ldquo;left double-quotation mark.&rdquo;
"left double-quotation mark."
</ul>
</ul>


Line 44: Line 44:
See [[CharacterTranslationException exception class]].
See [[CharacterTranslationException exception class]].
</dl>
</dl>
===Usage Notes===
==Usage notes==
<ul>
<ul>
<li>Unless the CharacterEncode argument is used, or
<li>Unless the CharacterEncode argument is used, or
Line 50: Line 50:
this function is generally not needed, because a Unicode string is
this function is generally not needed, because a Unicode string is
implicitly converted to EBCDIC when used in an EBCDIC context.
implicitly converted to EBCDIC when used in an EBCDIC context.
See the example in &ldquo;Examples,&rdquo; below.
See the example in "Examples," below.
<li>The [[EbcdicToUnicode (String function)|EbcdicToUnicode]] method
<li>The [[EbcdicToUnicode (String function)|EbcdicToUnicode]] method
converts an EBCDIC string to Unicode.
converts an EBCDIC string to Unicode.
</ul>
</ul>


===Examples===
==Examples==


The following example shows multiple calls of UnicodeToEbcdic.
The following example shows multiple calls of UnicodeToEbcdic.

Revision as of 04:09, 19 January 2011

Translate to Ebcdic (Unicode class)

This function converts a Unicode string to EBCDIC. As an option, untranslatable characters can be represented with XML style hexadecimal character references.

The UnicodeToEbcdic function is available as of version 7.3 of the Sirius Mods.

Syntax

%string = unicode:UnicodeToEbcdic[( [CharacterEncode= boolean])] Throws CharacterTranslationException

Syntax terms

%ebcdic
A string variable to receive the method object string translated to EBCDIC.
unicode
A Unicode string.
CharacterEncode=bool
The optional (name required) CharacterEncode argument is a Boolean:
  • If its value is False, the default, an exception is thrown if the input contains any Unicode character not translatable to EBCDIC.
  • If its value is True, any Unicode character not translatable to EBCDIC is replaced with the hexadecimal character reference of the character, and the ampersand character is replaced with &amp;. For example, the eight characters &#x201C; replace the Unicode "left double-quotation mark."

Exceptions

This function 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. See CharacterTranslationException exception class.

Usage notes

  • Unless the CharacterEncode argument is used, or you want to Catch a CharacterTranslationException, this function is generally not needed, because a Unicode string is implicitly converted to EBCDIC when used in an EBCDIC context. See the example in "Examples," below.
  • The EbcdicToUnicode method converts an EBCDIC string to Unicode.

Examples

The following example shows multiple calls of UnicodeToEbcdic. The U constant function is used in the example.

    %u Unicode Initial('&#x31;':U)
    Print %u:UnicodeToEbcdic

    %u = '1&#x80;2':U
    Print %u:UnicodeToEbcdic(CharacterEncode=True)
    Print %u:UnicodeToEbcdic

The result of the above fragment is:

    1
    1&#x0080;2
    CANCELLING REQUEST: MSIR.0751: Class STRING, function
      UNICODETOEBCDIC: CHARACTER TRANSLATIONEXCEPTION
      exception: Unicode character U+0080 without valid
      translation to EBCDIC at byte position 5 ...

Note: Because of the implicit conversion of Unicode strings (in this case to String),
the Print %u:UnicodeToEbcdic statements in the example above could be
replaced by Print %u statements and the results would be the same.