Class: String
Description
This method locates a substring within a string and extracts specific data from the substring, where the substring may be delimited by two delimiters. The behavior largely depends on whether label is empty or non-empty.
If label and majorDelim are both empty, then this method returns exactly the same value as StringObject.extract(position). The value of subDelim is ignored.
If label is the empty string and majorDelim is not the empty string, then this method returns exactly the same value as StringObject.piece(majorDelim, position). The value of subDelim is ignored.
If label is not the empty string, then majorDelim.length() will be 1. If subDelim is not the empty string, then subDelim.length() will also be 1. In this case, the method locates a majorDelim delimited field that starts with label (followed by subDelim). It then returns the subDelim delimited subfield following label specified by position.
If label occurs more than once, the leftmost occurrence is used
This method replaces the $$GET^USUB() function.
Syntax
StringObject.getSub(String label,String majorDelim,
String subDelim,Number position)
Parameters
label |
A group of characters that comprise the substring marker with a string. The default value is the empty string. |
majorDelim |
The single character delimiter that separates fields of the string. The default value is the empty string. |
subDelim |
The single character delimiter that separates the label and its subfields. The default value is majorDelim. |
position |
The position of the subfield to return. The default value is 1. |
Returns
A String.
When Became Available
v6.4
Example
type String STR = "L1#S11#S12;L2#S21#S22#S23;L3#S31"
// label and majorDelim both empty, "?" ignored
type String XTR = STR.getSub(,,"?",3) // "#"
// label empty, majorDelim not empty, "?" ignored again
type String XTR = STR.getSub(,"#","?",3) // "S12;L2"
// a more typical example
type String SUB = STR.getSub("L2",";","#",3) // "S23"