Returns the numbers of columns required to display a given string on the screen or printer. The format of the $ZWIDTH() function is:
The expression is the string which $ZWIDTH() evaluates for display length. If the expression contains a code-point value that is not a valid character in Unicode, $ZWIDTH() generates a run-time error.
If the expression contains any non-graphic characters, the $ZWIDTH() function does count not those characters.
If the string contains any escape sequences containing graphical characters (which they typically do), $ZWIDTH() includes those characters in calculating its result, as it does not do escape processing. In such a case, the result many be larger than the actual display width.
The ZWIDTH() function triggers a run-time error if it encounters a malformed byte sequence irrespective of the setting of "BADCHAR".
With character set UTF-8 specified, the $ZWIDTH() function uses the ICU's glyph-related conventions to calculate the number of columns required to represent the expression.
GTM>set NG=$char($$FUNC^%HD("200B")) GTM>set S=$char(26032)_NG_$CHAR(26033) GTM>W $ZWidth(STR) 4 GTM>
In the above example, the local variable NG contains a non-graphic character which does not display between two double-width characters in Unicode.
GTM>write $zwidth("The rain in Spain stays mainly in the plain.") 44 GTM>set A="主要雨在西班牙停留在平原" GTM>write $length(A) 12 GTM>write $zwidth(A) 24
In the above example, the $ZWIDTH() function returns 24 because each character in A occupies 2 columns when they are displayed on the screen or printer.