Was this helpful?
Split Method
The Split method splits the StringObject contents into an array of StringObjects and returns them.
This method has the following syntax:
array of StringObject = StringObject.Split(delimiter = varchar(256)
          [, ignorecase = integer] [, backwards = integer]
          [, exactrows = integer] [, minrows = integer]
          [, includedelimiter = integer]
          [, preserveblanklasttoken = integer]
          [, preserveleadingwhitespace = integer])
This method has the following parameters:
delimiter
(Required) Specifies one or more delimiters used to split the string into substrings. Multiple parameters must be separated by the character pair "\," (backslash, comma).
ignorecase
Specifies whether delimiters within the StringObject will be searched for, ignoring case (TRUE) or not (FALSE). The default is FALSE.
backwards
Specifies whether delimiters within the StringObject will be searched for, starting from the end (TRUE) or not (FALSE). The search starts with the leftmost character of the text being searched for, not the rightmost character. The default is FALSE.
exactrows
Specifies the exact number of rows that the returned array must contain. If there are more delimiters in the StringObject than exactrows specifies, the final entry may contain delimiters; if there are fewer delimiters, the final entry or entries will contain empty StringObjects.
minrows
Specifies the minimum number of rows that the returned array must contain. If there are fewer delimiters in the StringObject than minrows specifies, the final entry or entries will contain empty StringObjects.
includedelimiter
Specifies whether each delimiter found within the StringObject will be added to the returned array (TRUE) or not (FALSE). The default is FALSE.
preserveblanklasttoken
Specifies whether the last token (the string following the last delimiter) will be included if it is actually blank. The default is FALSE.
preserveleadingwhitespace
Specifies whether substrings created by the split will preserve any leading whitespace (TRUE) or not (FALSE). The default is FALSE.
Split points are identified by one or more delimiters; delimiters can be any length up to 256 characters. Multiple delimiters (themselves separated by "\," in the parameter value) are applied in round-robin fashion, and the nearest match is used. Leading whitespace is removed from each token by default, unless preserveleadingwhitespace=TRUE.
The return array can optionally include the delimiters as StringObjects (the number of rows returned becomes 2n-1). This enables global character and substring replacement.
Matching can be case-insensitive or backwards; the number of rows returned can be specified as an exact number or a minimum.
This method returns an array of StringObject.
Some examples of Split() usage:
initialize()=
declare
    soarray = array of stringobject;
    so = stringobject;
    idx = integer not null default 1;
enddeclare
{
    // Empty StringObject array
    so = so.Join(strings = soarray);
    curframe.trace(text = 'Join Empty StringObject array: ' + so.value);
 
    // StringObject array with 3 records and a '$' delimiter.
    soarray[1].value = 'Line1_';
    soarray[2].value = 'Line2_';
    soarray[3].value = 'Line3_';
    so = so.Join(strings = soarray, delimiter = '$');
    curframe.trace(text = 'Join StringObject array with 3 records: ' + so.value );
    curframe.trace(text = HC_NEWLINE + 'Split with delimiter = ' + HC_QUOTE + '$' + HC_QUOTE);
    soarray = so.Split(delimiter = '$');
    for idx = 1 to soarray.lastrow do
        curframe.Trace(text = '[' + varchar(idx) + ']: ' + soarray[idx].value);
    endfor;
 
  curframe.trace(text = HC_NEWLINE + 'Split with delimiter = ' + HC_QUOTE +
'$' + HC_QUOTE +     'and backwards = 1');
    soarray = so.Split(delimiter = '$', backwards = 1);
    for idx = 1 to soarray.lastrow do
        curframe.Trace(text = '[' + varchar(idx) + ']: ' + soarray[idx].value);
    endfor;
    
    curframe.trace(text = HC_NEWLINE + 'Split with delimiter = ' + HC_QUOTE +
'$' + HC_QUOTE + 'and backwards = 1 and includedelimiter = 1');
    soarray = so.Split(delimiter = '$', backwards = 1, includedelimiter = 1);
    for idx = 1 to soarray.lastrow do
        curframe.Trace(text = '[' + varchar(idx) + ']: ' + soarray[idx].value);
    endfor;
}
Example produces the following in the Trace window:
Join Empty StringObject array:
Join StringObject array with 3 records: Line1_$Line2_$Line3_
 
Split with delimiter = '$'
[1]: Line1_
[2]: Line2_
[3]: Line3_
 
Split with delimiter = '$'and backwards = 1
[1]: Line3_
[2]: Line2_
[3]: Line1_
 
Split with delimiter = '$'and backwards = 1 and includedelimiter 1
[1]: Line3_
[2]: $
[3]: Line2_
[4]: $
[5]: Line1_
Last modified date: 06/25/2024