EXTRACT Function¶
Material prepared from M Programming Book [WALTERS1997]
Page 65.
Command¶
$EXTRACT(target[,start[,end]])
Description¶
$EXTRACT(target[,start[,end]])
takes a string and two optional integers as arguments and returns a substring.
- Returns the first character of the target string if the start argument is omitted.
- If
start
orend
are out of bounds then it returns only valid characters from the target string. - If
end
<start
then it returns""
.
Example¶
; Writes "T"
S X=$EXTRACT("Thomas Rozanski") W X
; Writes "o"
S X=$EXTRACT("Thomas Rozanski",3) W X
; Writes nothing
S X=$EXTRACT("Thomas Rozanski",0) W X
; Writes nothing
S X=$EXTRACT("Thomas Rozanski",999) W X
; Writes "Thomas Rozanski"
S X=$EXTRACT("Thomas Rozanski",0,999) W X
; Writes "Tho"
S X=$EXTRACT("Thomas Rozanski",1,3) W X
; Writes nothing
S X=$EXTRACT("Thomas Rozanski",3,1) W X