☜ | $EXTRACTM[UMPS] by Example | ☞ |
Introduced in the 1977 ANSI M[UMPS] language standard.
This function returns substrings of strings that are specified as parameters.
Reference | Value | |
---|---|---|
$Extract("ABCDEFG",2) | "B". | |
$Extract("ABCDEGF",2,5) | "BCDE" |
Assume that X="ABCDEF12345GHI".
Reference | Value | |
---|---|---|
$Extract(X,20) | empty string | |
$Extract(X,10,99) | "45GHI" | |
$Extract("",2,3) | empty string |
Assume that X="12345619481021MIN123a" and contains a ‘fixed length’ data record:
Registration-number
Reference | Value | |
---|---|---|
$Extract(X,1,6) | 123456 |
Birth date
Reference | Value | |
---|---|---|
$Extract(X,7,14) | 19481021 |
Gender
Reference | Value | |
---|---|---|
$Extract(X,15) | "M" |
Department
Reference | Value | |
---|---|---|
$Extract(X,16,17) | "IN" |
Room-number
Reference | Value | |
---|---|---|
$Extract(X,18,21) | "123a" |
Set X="ABCDE"
Reference | Value | |
---|---|---|
$Extract(X,1) | "A" | |
$Extract(X,2) | "B" | |
$Extract(X,1,2) | "AB" | |
$Extract(X,1,4) | "ABCD" | |
$Extract(X,0,100) | "ABCDE" | |
$Extract(X,1.92) | "A" | |
$Extract(X,99) | "" | |
$Extract(X,–3) | "" | |
$Extract(X,3,2) | "" |
Set A(1)="2BC"
Reference | Value | |
---|---|---|
$Extract(A(1),A(1)) | "B" |
Set X="98765"
In the examples below, the open square character (⋥) is displayed
where the resulting strings contain spaces, so that the number
if space-characters becomes visible.
Reference | Value | |
---|---|---|
Set Y=$Extract(X,3,7) | Y="765" | |
Set Y=Y_"⋥⋥⋥⋥⋥" | Y="765⋥⋥⋥⋥⋥" | |
Set Y=$Extract(Y,1,5) | Y="765⋥⋥" |
or, in one formula:
Set Y=$Extract($Extract(X,3,7)_"⋥⋥⋥⋥⋥",1,5)
Addition in the 1995 ANSI M[UMPS] Language Standard:
It is allowed to specify a reference to $Extract on the left hand side of the equal sign in a Set command.
Set X="ABCDEFG"
Reference | Value | |
---|---|---|
Set $Extract(X,3)="a" | X="ABaDEFG" | |
Set $Extract(X,2)="xxx" | X="AxxxaDEFG" | |
Set $Extract(X,2,6)="" | X="AEFG" |
Set X="ABCDEFG"
Reference | Value | |
---|---|---|
Set $Extract(X,2,3)="PQ" | X="APQDEFG" | |
Set $Extract(X,2,6)="=" | X="A=G" | |
Set $Extract(X,11,12)="PQ" | X="A=G⋥⋥⋥⋥⋥⋥⋥PQ" | |
Set $Extract(X,2)="PQ" | X="APQG⋥⋥⋥⋥⋥⋥⋥PQ" | |
Set $Extract(X)="ZzZ" | X="ZzZPQG⋥⋥⋥⋥⋥⋥⋥PQ" |
Examples with naked references:
$Extract(VALUE)
Set ^ABC(1,2)="reset naked indicator"
; naked indicator is now ^ABC(1,
Set ^(3,4)=$Extract(^(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,
$Extract(VALUE,CHAR)
Set ^ABC(1,2)="reset naked indicator"
; naked indicator is now ^ABC(1,
Set ^(3,4)=$Extract(^(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,
$Extract(VALUE,FROM,TO)
Set ^ABC(1,2)="reset naked indicator"
; naked indicator is now ^ABC(1,
Set ^(3,4)=$Extract(^(5,6),^(7,8),^(9,10))
; 1. fetch ^(5,6) = ^ABC(1,5,6)
; 2. fetch ^(7,8) = ^ABC(1,5,7,8)
; 3. fetch ^(9,10) = ^ABC(1,5,7,9,10)
; 4. store ^(3,4) = ^ABC(1,5,7,9,3,4)
; naked indicator is now: ^ABC(1,5,7,9,3,
Set $Extract(VALUE,FROM,TO)=VALUE
Set ^ABC(1,2)="reset naked indicator"
; naked indicator is now ^ABC(1,
Set $Extract(^(3,4),^(5,6),^(7,8))=^(9,10)
; 1. fetch ^(5,6) = ^ABC(1,5,6)
; 2. fetch ^(7,8) = ^ABC(1,5,7,8)
; 3. fetch ^(9,10) = ^ABC(1,5,7,9,10)
; 4: if ^ABC(1,5,7,8) < ^ABC(1,5,6) or if
^ABC(1,5,7,8) < 1
; don’t store, naked indicator is ^ABC(1,5,7,9,
; else continue
; 5. fetch/store ^(3,4) = ^ABC(1,5,7,9,3,4)
; naked indicator is now: ^ABC(1,5,7,9,3,
Copyright © Standard Documents; 1977-2024 MUMPS Development Committee;
Copyright © Examples: 1995-2024 Ed de Moel;
Copyright © Annotations: 2003-2008 Jacquard Systems Research
Copyright © Annotations: 2008-2024 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 15-Nov-2023, 13:08:30.
For comments, contact Ed de Moel (demoel@jacquardsystems.com)