## $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) =

; 2. store ^(3,4) =

; naked indicator is now:

$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) =

; 2. fetch ^(7,8) =

; 3. store ^(3,4) =

; naked indicator is now:

Copyright © Standard Documents; 1977-2018 MUMPS Development Committee;

Copyright © Examples: 1995-2018 Ed de Moel;

Copyright © Annotations: 2003-2008 Jacquard Systems Research

Copyright © Annotations: 2008-2018 Ed de Moel.

*The information in this page is
NOT authoritative and subject to be modified
at any moment.Please consult the
appropriate (draft) language standard for an
authoritative definition.*

*Some specifications are "approved
for inclusion in a future standard". Note
that the MUMPS Development Committee cannot
guarantee that such future standards will
indeed be published.*

This page most recently updated on 13-Sep-2014, 17:19:47 .

For comments, contact Ed de Moel (demoel@jacquardsystems.com)