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 |
Reference | Value | |
---|---|---|
$EXTRACT(X,7,14) | 19481021 |
Reference | Value | |
---|---|---|
$EXTRACT(X,15) | "M" |
Reference | Value | |
---|---|---|
$EXTRACT(X,16,17) | "IN" |
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 tilde-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:
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,
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.