function modstr = replace(origstr,oldstr,newstr)
%REPLACE Replace string with another.
%   
%   MODIFIEDSTR = REPLACE(ORIGSTR,OLDSUBSTR,NEWSUBSTR) 
%   
%   Limitations:
%   Pattern objects are not supported.
%   
%   See also REPLACE.
%   


%   Copyright 2016-2020 The MathWorks, Inc.

narginchk(3,3);
% PATTERN is currently not supported
matlab.bigdata.internal.util.errorIfPatternInput('distributed', origstr, ...
    oldstr, newstr);

% Replacement values are always gathered
[oldstr, newstr] = gather(oldstr, newstr);

% If the first input is not distributed, just use the normal function.
if ~iscodistributed(origstr)
    modstr = replace(origstr,oldstr,newstr);
    return;
end

% Run as element-wise in the first input
modstr = codistributed.pElementwiseOp(@(x) replace(x, oldstr, newstr), origstr);
