function s = extractBefore(str,endStr)
%EXTRACTBEFORE Create a string from part of a larger string.
%   S = EXTRACTBEFORE(STR, END)
%
%   Limitations:
%   Pattern objects are not supported.
%
%   See also TALL/STRING.

%   Copyright 2016-2020 The MathWorks, Inc.

narginchk(2,2);

% First input must be tall string.
tall.checkIsTall(upper(mfilename), 1, str);
str = tall.validateType(str, mfilename, {'string'}, 1);

% Pattern objects are not supported
matlab.bigdata.internal.util.errorIfPatternInput('tall', endStr);

% Treat all inputs element-wise, wrapping char arrays if used
endStr = wrapPositionInput(endStr);
s = elementfun(@extractBefore, str, endStr);

% Output is always the same size and type as the first input.
s.Adaptor = str.Adaptor;
end
