javascript - shorten string to fit into a certain # of lines
Posted
by Mala
on Stack Overflow
See other posts from Stack Overflow
or by Mala
Published on 2010-05-17T23:46:02Z
Indexed on
2010/05/17
23:50 UTC
Read the original article
Hit count: 554
Hi
I have a string that must fit into a box, and must be at most 3 lines long. To shorten it, I plan to truncate it and end it with '...'. I could shorten it to a certain # of characters but if i make it look good with "wwwwwwwww [...] wwww" it won't look right with "iiiiiiiiiii [...] iiii".
Is there some way I can shorten it by how much space the string would take up, as opposed to how many characters there are in a string without using a fixed-width font?
Mala
ps. Please no "simply create an image of '...' and overlay it over the end of the line" hacks or similar - I actually want to shorten the string to the appropriate length
© Stack Overflow or respective owner