Returns the numbers of columns required to display a given string on the screen or printer. The format of the $ZWIDTH() function is:
$ZW[IDTH] (expr)
The expression is the string which $ZWIDTH() evaluates for display length. If the expression contains a code-point value that is not a valid UTF-8 character, $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.
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.
Note | |
---|---|
When in "NOBADCHAR" mode, $ZWIDTH() returns give any bad characters a length of zero (0), which may or may not match the behavior of any device used to display the string. |
Example:
GTM>set NG=$char($$FUNC^%HD("200B")) GTM>set S=$char(26032)_NG_$CHAR(26033) GTM>W $ZWidth(S) 4 GTM>
In the above example, the local variable NG contains a non-graphic character which does not display between two double-width UTF-8 characters.
Example:
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 local variable A occupies 2 columns when they are displayed on the screen or printer.