$ZWidth()

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)

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] 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.

Examples of $ZWIDTH()

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.