M[UMPS] Functions - $L[ENGTH]

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


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,


This document is © Ed de Moel, 1995-2005.
It is part of a book by Ed de Moel that is published under the title "M[UMPS] by Example" (ISBN 0-918118-42-5).
Printed copies of the book are no longer available.