function D = censor(str, A)
% Replace all occurrences of string str in character matrix A, regardless
% of case, with X's.
% A is a matrix of characters.
% str is a string. Assume that str is never split across two lines.
% D is A with X's replacing the censored string str.

D= A;
B= lower(A);
s= lower(str);
ns= length(str);
[nr,nc]= size(A);

% Build a string of X's of the right length
Xs= char(zeros(1,ns)); % not necessary, but good practice to
% initialize to correct size and type
for k= 1:ns
Xs(k)= 'X';
end

% Traverse the matrix to censor string str
for r= 1:nr
for c= 1:nc-ns+1
if strcmp(s,B(r,c:c+ns-1))==1
D(r,c:c+ns-1)= Xs;
end
end
end