Caché ObjectScript Reference
[Home] [Back] [Next]
InterSystems: The power behind what matters   

Converts a two-byte string to a number.
string A string. It can be a value, a variable, or an expression. It must be a minimum of two bytes in length.
position Optional — A starting position in the string, expressed as a positive integer. The default is 1. Position is counted in single bytes, not two-byte strings. The position cannot be the last byte in the string, or beyond the end of the string. A numeric position value is parsed as an integer by truncating decimal digits, removing leading zeros and plus signs, etc.
The value that $ZWASCII returns depends on the parameters you use.
Upon successful completion, $ZWASCII always returns a positive integer. $ZWASCII returns -1 if string is of an invalid length, or position is an invalid value.
The following example determines the numeric interpretation of the character string "ab":
It returns 25185.
The following examples also return 25185:
  WRITE !,$ZWASCII("ab",1)
  WRITE !,$ZWASCII("abxx",1)
  WRITE !,$ZWASCII("xxabxx",3)
In the following examples, string or position are invalid. The $ZWASCII function returns –1 in each case:
  WRITE !,$ZWASCII("aba",3)
  WRITE !,$ZWASCII("ababab",99)
  WRITE !,$ZWASCII("ababab",0)
  WRITE !,$ZWASCII("ababab",-1)
$ZWASCII is similar to $ASCII except that it operates on two byte (16-bit) words instead of single 8-bit bytes. For four byte (32-bit) words, use $ZLASCII; For eight byte (64-bit) words, use $ZQASCII.
$ZWASCII(string,position) is the functional equivalent of:
The $ZWCHAR function is the logical inverse of $ZWASCII. For example:
returns: 25185.
   WRITE $ZWCHAR(25185)
returns “ab”.
See Also

Send us comments on this page
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA