$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)
[Note] Note

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.

Examples of $ZWIDTH()

Example:

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.

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 A occupies 2 columns when they are displayed on the screen or printer.