function truncatedStringArr = getTruncatedStringArray(strArray, width, displayConfiguration)
% Construct the truncated version of the input string array based on the
% input width

% Copyright 2020-2021 The MathWorks, Inc.
arguments
    strArray string
    width (1,1) double
    displayConfiguration (1,1) matlab.display.DisplayConfiguration
end
% Transform string array into a char array to allow character indexing
charColumnVec = char(strArray);
numColumns = size(charColumnVec,2);

% Iterate over each of the characters in the array and append them into
% the resultin trucatedStringArr if they fit in the available width
for i = 1:numColumns
    if any(characterWidthForStringArray(displayConfiguration, charColumnVec(:,1:i)) > width)
        truncatedStringArr = string(charColumnVec(:,1:(i-1)));
        break;
    else
        truncatedStringArr = string(charColumnVec(:,1:i));
    end
end
end