RosettaCodeData/Task/Binary-strings/PL-I/binary-strings.pli

23 lines
1003 B
Plaintext

/* PL/I has immediate facilities for all those operations except for */
/* replace. */
s = t; /* assignment */
s = t || u; /* catenation - append one or more bytes. */
if length(s) = 0 then ... /* test for an empty string. */
if s = t then ... /* compare strings. */
u = substr(t, i, j); /* take a substring of t beginning at the */
/* i-th character andcontinuing for j */
/* characters. */
substr(u, i, j) = t; /* replace j characters in u, beginning */
/* with the i-th character. */
/* In string t, replace every occurrence of string u with string v. */
replace: procedure (t, u, v);
declare (t, u, v) character (*) varying;
do until (k = 0);
k = index(t, u);
if k > 0 then
t = substr(t, 1, k-1) || v || substr(t, k+length(u));
end;
end replace;