MEMREPLACE
MEMREPLACE fills a target buffer with the contents of a source buffer with one or more occurrences of a specified third buffer replaced by a fourth buffer, and returns a size_t value that indicates the number of bytes that are written to the target buffer.
- p
- Specifies the address of the target buffer.
- m
- Specifies the length in bytes of the target buffer. The length must be non-negative. It must have a computational type and is converted to the size_t type.
- q
- Specifies the address of the source buffer.
- n
- Specifies the length in bytes of the source buffer. The length must be non-negative. It must have a computational type and is converted to the size_t type.
- f
- Specifies the address of the buffer containing the bytes that will be replaced.
- x
- Specifies the length in bytes of the buffer f. The length must be non-negative. It must have a computational type and is converted to the size_t type.
- t
- Specifies the address of the buffer containing the bytes that will be used to replace the bytes of the buffer f within the buffer p.
- y
- Specifies the length in bytes of the buffer t. The length must be non-negative. It must have a computational type and is converted to the size_t type.
- s
- An optional expression that specifies the location within the source buffer from where to start searching for the buffer defined by f and x. It must have a computational type and is converted to the size_t type. The default value for s is 1. If s is less than 1 or if s is greater than 1 + n, zero bytes will be written to the target buffer.
- i
- An optional expression that specifies the maximum number of times f should be replaced by t. It must have a computational type and is converted to the size_t type. The default value of i is 1. i must be non-negative. If the value of i is 0, all occurrences of f in source buffer will be replaced by t.
The returned value depends on the address of the target buffer
or the size of the target buffer:
- If the address of the target buffer is zero (null), the number of bytes that would be written is returned.
- If the target buffer is not large enough, a value of -1 is returned.
- If the target buffer is large enough, the number of bytes that are written to the buffer is returned.
dcl ein char(50) var value('reserved from #date# till #date#.');
dcl aus char(80) var;
dcl cx fixed bin(31);
dcl f char(6);
dcl t char(10);
f = '#date#';
t = '2018/05/01';
cx = memreplace( addrdata(aus), maxlength(aus),
addrdata(ein), length(ein),
addrdata(f), length(f),
addrdata(t), length(t));
/* cx = 37 */
/* aus = 'reserved from 2018/05/01 till #date#.' */
cx = memreplace( addrdata(aus), maxlength(aus),
addrdata(ein), length(ein),
addrdata(f), length(f),
addrdata(t), length(t),16,1);
/* cx = 37 */
/* aus = 'reserved from #date# till 2018/05/01.' */
cx = memreplace( addrdata(aus), maxlength(aus),
addrdata(ein), length(ein),
addrdata(f), length(f),
addrdata(t), length(t),,0);
/* cx = 41 */
/* aus = 'reserved from 2018/05/01 till 2018/05/01.' */