AsciiToEbcdic (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
 
(28 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Template:String:AsciiToEbcdic subtitle}}
{{Template:String:AsciiToEbcdic subtitle}}


This [[Intrinsic classes|intrinsic]] function converts an ASCII (ISO-8859-1) string to EBCDIC
<var>AsciiToEbcdic</var> is an [[Intrinsic classes|intrinsic]] function that converts an ASCII (ISO-8859-1) string to EBCDIC using the current [[Unicode tables]]. Optionally, untranslatable characters are represented with character references.
using the current <var>Unicode</var> tables.
Optionally,
untranslatable characters are represented with character references.


The <var>AsciiToEbcdic</var> function is available as of version 7.3 of the <var class=product>Sirius Mods</var>.
==Syntax==
==Syntax==
{{Template:String:AsciiToEbcdic syntax}}
{{Template:String:AsciiToEbcdic syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%ebcdic</th>
<tr><th>%outString</th>
<td>A string variable to receive the method object string translated to EBCDIC.             </td></tr>
<td>A string variable to receive the method object <var class="term">string</var> translated to EBCDIC.</td></tr>
 
<tr><th>string</th>
<tr><th>string</th>
<td>A string that is presumed to consist of ASCII characters.                               </td></tr>
<td>The input string, which is presumed to consist of ASCII characters.</td></tr>
<tr><th>CharacterEncode=bool</th>
 
<td>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 ASCII character not translatable to EBCDIC.               *If its value is ''''True'''', any ASCII character not translatable to EBCDIC is replaced with the XML style hexadecimal character reference of the character, and the ampersand character is replaced with ''''&amp.amp;''''.                                                                                                   For instance, the six characters '&amp;#x90;' replace the ASCII                     ''Device Control <var>String</var>'' character (X'90').                                 A similar example is shown below.</td></tr>
<tr><th><var>CharacterEncode</var></th>
<td>The optional, [[Notation conventions for methods#Named parameters|name required]], <var>CharacterEncode</var> argument is a <var>[[Boolean enumeration]]</var>.  If its value is:
<ul>
<li><var>False</var>, the default, an exception is thrown if the input <var class="term">string</var> contains any ASCII character not translatable to EBCDIC.
 
<li><var>True</var>, any ASCII character not translatable to EBCDIC is replaced with the XML style hexadecimal character reference of the character, and the ampersand character is replaced with <code>'&amp;amp;'</code>.
 
<li>For instance, the six characters <code>&amp;#x90;</code> replace the ASCII "Device Control String" character (X'90'). A similar example is shown below.
</ul>
</td></tr>
</table>
</table>


===Exceptions===
==Exceptions==
 
<var>AsciiToEbcdic</var> can throw the following exception:
This [[Intrinsic classes|intrinsic]] function can throw the following exception:
<dl>
<dl>
<dt>[[CharacterTranslationException]]
<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==
*More information is available about the [[Unicode Tables|Unicode tables]].
<ul><li>More information is available about the [[Unicode tables]].
*The inverse of the <var>AsciiToEbcdic</var> method is [[EbcdicToAscii (String function) | EbcdicToAscii]].
<li>The <var>AsciiToEbcdic</var> function is available as of <var class="product">Sirius Mods</var> version 7.3.</ul>


==Examples==
==Examples==
The following fragment shows calls of <var>AsciiToEbcdic</var> against strings with and without non-translatable characters.
<p class="code">%a string Len 20
%a = '31':X
Print %a:AsciiToEbcdic


The following fragment shows calls of <var>AsciiToEbcdic</var> against strings with and
%a = '318132':[[X (String function)|X]]
without non-translatable characters.
Print %a:AsciiToEbcdic(CharacterEncode=True)
    %a <var>String</var> Len 20
Print %a:AsciiToEbcdic
    %a = [[Intrinsix X function|'31':X]]
</p>
    Print %a:<var>AsciiToEbcdic</var>
 
    %a = '318132':X
    Print %a:<var>AsciiToEbcdic</var>(CharacterEncode=True)
    Print %a:<var>AsciiToEbcdic</var>
The result is:
The result is:
    1
<p class="output">1
    1&amp;#x81;2
1&amp;#x81;2
    CANCELLING REQUEST: MSIR.0751: Class STRING, function ASCIITOEBCDIC: CHARACTER TRANSLATIONEXCEPTION
CANCELLING REQUEST: MSIR.0751: Class STRING, function ASCIITOEBCDIC: CHARACTERTRANSLATIONEXCEPTION exception: ASCII character X'81' without valid translation to EBCDIC at byte position 1 ...
      exception: ASCII character X'81' without valid translation to EBCDIC at byte position 1 ...
</p>


==See also==
==See also==
[[List of intrinsic String methods]]
<ul><li>The inverse of the <var>AsciiToEbcdic</var> method is <var>[[EbcdicToAscii (String function) | EbcdicToAscii]]</var>.</ul>
 
{{Template:String:AsciiToEbcdic footer}}
[[Category:String methods|AsciiToEbcdic function]]
[[Category:Intrinsic methods]]

Latest revision as of 20:46, 15 February 2014

Convert ASCII string to EBCDIC (String class)


AsciiToEbcdic is an intrinsic function that converts an ASCII (ISO-8859-1) string to EBCDIC using the current Unicode tables. Optionally, untranslatable characters are represented with character references.

Syntax

%outString = string:AsciiToEbcdic[( [CharacterEncode= boolean])] Throws CharacterTranslationException

Syntax terms

%outString A string variable to receive the method object string translated to EBCDIC.
string The input string, which is presumed to consist of ASCII characters.
CharacterEncode The optional, name required, CharacterEncode argument is a Boolean enumeration. If its value is:
  • False, the default, an exception is thrown if the input string contains any ASCII character not translatable to EBCDIC.
  • True, any ASCII character not translatable to EBCDIC is replaced with the XML style hexadecimal character reference of the character, and the ampersand character is replaced with '&amp;'.
  • For instance, the six characters &#x90; replace the ASCII "Device Control String" character (X'90'). A similar example is shown below.

Exceptions

AsciiToEbcdic 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

  • More information is available about the Unicode tables.
  • The AsciiToEbcdic function is available as of Sirius Mods version 7.3.

Examples

The following fragment shows calls of AsciiToEbcdic against strings with and without non-translatable characters.

%a string Len 20 %a = '31':X Print %a:AsciiToEbcdic %a = '318132':X Print %a:AsciiToEbcdic(CharacterEncode=True) Print %a:AsciiToEbcdic

The result is:

1 1&#x81;2 CANCELLING REQUEST: MSIR.0751: Class STRING, function ASCIITOEBCDIC: CHARACTERTRANSLATIONEXCEPTION exception: ASCII character X'81' without valid translation to EBCDIC at byte position 1 ...

See also