SETEXTRACT        Extract delimited substring from a string

Top  Previous  Next

Syntax:

SETEXTRACT

[ variable ]  =  [ string ] [ delim ] [ num ]

Arguments:

[ variable ]

Variable to assign; if the variable does not previously exist it is created.

 

[ string ]

Variable or string defining the value from which the substring is to be extracted.

 

[ delim ]

Variable or string defining the delimiter that separates sub-strings within [ string ].

 

[ num ]

Variable, string, or numeric constant defining the occurrence of delimited substring to extract.

Options:

none

 

 

 

This script command extracts the specified occurrence [ num ] of a delimited substring (excluding the delimiters themselves) from [ string ] and saves the result in [ variable ]. The delimiter may be one or more characters and is specified in [ delim ].

 

The beginning and end of [ string ] are seen as delimiters.

 

Consider the following example.

 

;; extract "is" from string

SET string = "this is a string"

;; "is" is the 2nd occurrence delimited by space (" ")

SETEXTRACT substring = string " "  2

;; substring now contains "is"

 

;; extract extension from file name of unknown size

;; for example, file name could be:

;; file.ext

;; file.file1.ext

;; file.file1.file2.ext

SETSUBSTR depth = filename "."

SETNUM depth = depth + 1

SETEXTRACT extension = filename "."  depth

;; extension now contains "ext"

 

Related Command(s):SET, SETRIGHT, SETLEFT, SETLEN, SETMID, SETSUBSTR