## \$LENGTH

### M[UMPS] by Example

Introduced in the 1977 ANSI M[UMPS] language standard.

This function returns information about the length of a string.

Reference Value \$Length("ABC") 3 \$Length("ABCD354") 7

Set X="ABCD"

Reference Value \$Length(X) 4 \$Length("") 0 (zero)

Set X=""

Reference Value \$Length(X) 0 (zero)

Set X="ABC"

Reference Value \$Length(X) 3

Set X="123456789"

Reference Value \$Length(X) 9

Set X=""

Reference Value \$Length(X) 0

Addition in the 1990 ANSI M[UMPS] language standard (count pieces separated by value of second parameter):

Reference Value \$Length("A.B.C",".") 3 \$Length("A.B.C","-") 1 \$Length("A-A-A-A","A-") 4, not 3.5

The value of \$Length("abababaaba","aba") is seemingly open to interpretation, after all, the string "abababaaba"can be segmented in various ways, and the function value would vary with the interpretation

• aba b aba aba, which would justify a value of 4
• ab aba ba aba, which would justify a value of 3

Because the language standard stipulates that in all cases where a choice exists, strict left-to-right evaluation prevails, the second interpretation is the one that is endorsed by the language standard.

Examples with naked references:

\$Length(VALUE)
Set ^ABC(1,2)="reset naked indicator"
; naked indicator is now ^ABC(1,
Set ^(3,4)=\$Length(^(5,6))

; 1. fetch ^(5,6) = ^ABC(1,5,6)
; 2. store ^(3,4) = ^ABC(1,5,3,4)
; naked indicator is now: ^ABC(1,5,3,

\$Length(VALUE,SUBSTR)
Set ^ABC(1,2)="reset naked indicator"
; naked indicator is now ^ABC(1,
Set ^(3,4)=\$Length(^(5,6),^(7,8))

; 1. fetch ^(5,6) = ^ABC(1,5,6)
; 2. fetch ^(7,8) = ^ABC(1,5,7,8)
; 3. store ^(3,4) = ^ABC(1,5,7,3,4)
; naked indicator is now: ^ABC(1,5,7,3,