Start of change

COLLAPSE

Start of change

Start of changeCOLLAPSE returns a string that reduces all multiple occurrences of a character to one, starting from an optional specified position. The leading and trailing instances of that character are also trimmed.End of change

Read syntax diagramSkip visual syntax diagram
>>-COLLAPSE(x,y-+----+-)---------------------------------------><
                '-,n-'     

x
A string expression. x specifies the string from which all multiple occurrences of the character defined by y are reduced to one. x must have the CHARACTER attribute.
y
An expression. y must have the type CHARACTER(1) NONVARYING. The leading and trailing instances of y are also trimmed.
n
An expression. n specifies the location within x at which to begin to locate the first occurrences of y.
n must have a computational type and is converted to type size_t. The default value for n is 1.
  • If n < 1, the default value 1 is used.
  • If n > length(x), the full string of x is returned.

Example

dcl s1 char value( ' abc  :  def   gh  ' );
dcl s  char(20);
 
s = collapse(s1, ' ', 1);
      /* 'abc : def gh ' */
s = collapse(s1, ' ', 2);
      /* ' abc : def gh ' */
s = collapse(s1, ' ', index(s1,':'));
      /* ' abc  : def gh ' */
End of change
End of change