Truncate the text
The maximal length must be
maxlength, so we need to cut it a little shorter, to give space for the ellipsis.
Note that there is actually a single unicode character for an ellipsis. That’s not three dots.
Create a function
truncate(str, maxlength) that checks the length of the
str and, if it exceeds
maxlength – replaces the end of
str with the ellipsis character
"…", to make its length equal to
The result of the function should be the truncated (if needed) string.
truncate("What I'd like to tell on this topic is:", 20) = "What I'd like to te…" truncate("Hi everyone!", 20) = "Hi everyone!"