RSUBSTR Function

RSUBSTR (x, p, l, r) ;

The RSUBSTR function returns an $m \times n$ matrix with substrings of the input matrix with new strings.

The inputs to the RSUBSTR subroutine are as follows:

x

is any $m \times n$ character matrix.

p

is an $m \times n$ matrix or a scalar that determines the starting positions for substrings to be replaced.

l

is an $m \times n$ matrix or a scalar that determines the lengths of substrings to be replaced.

r

is an $m \times n$ matrix or a scalar that specifies the replacement strings.

If $l$ is zero, the replacement string in $r$ is simply inserted into the input matrix $x$ at the position indicated by $p$.

For example, the following statements replace the first two characters of each entry in the matrix X with the corresponding entry in the matrix R:

x = {abc def ghi,jkl mno pqr};
r = {z y x, w v u};
p = 1;
l = 2;
c=rsubstr(x,p,l,r);
print x, c;

Figure 24.16: Substring Replacement

x
ABC DEF GHI
JKL MNO PQR

c
ZC YF XI
WL VO UR