REPLACE
REPLACE returns a string with one or more occurrences of a substring replaced by another substring.
- x
- A string expression that specifies the string within which the occurrences of the substring f will be replaced by the substring t. x must have a CHARACTER type.
- f
- A string expression that specifies the substring that will be replaced within the string x. f must have a CHARACTER type.
- t
- A string expression that specifies the substring that will be used to replace the substring f within the string x. t must have a CHARACTER type.
- n
- An optional expression that specifies a location within the string x, from where the compiler begins searching for the substring f. n must have a computational type and is converted to FIXED BINARY(31,0). The default value for n is 1. If n is less than 1 or greater than the length(x), the STRINGRANGE condition will be raised if enabled, and the result will be a null character string.
- i
- An optional expression that specifies the maximum number of times that the substring f should be replaced by the substring t. i must have a computational type and is converted to FIXED BINARY(31,0). The default value for i is 1. i must be non-negative. If i is 0, all occurrences of the substring f in the string x will be replaced by the substring t.
dcl ein char(50) var init
( 'reserved from #date# till #date#.' );
dcl aus char(80) var;
dcl f char(6);
dcl t char(10);
f = '#date#';
t = '2018/05/01';
aus = replace( ein, f, t );
/* 'reserved from 2018/05/01 till #date#.' */
aus = replace( ein, f, t, 16 );
/* 'reserved from #date# till 2018/05/01.' */
aus = replace( ein, f, t, 1
, 2 );
/* 'reserved from 2018/05/01 till 2018/05/01.' */
aus = replace( ein, f, t, 16, 1 );
/* 'reserved from #date# till 2018/05/01.' */
aus = replace( ein, f, t, 1, 0 );
/* 'reserved from 2018/05/01 till 2018/05/01.' */