Contracting text to a fixed width
tsj at unimelb.edu.au
Thu Feb 22 00:18:35 EST 2007
I'm looking for a way to contract unwrapped lines of text to a fixed width -
primarily for use in a table where the width of columns is
variable/adjustable and often narrower than the text each 'cell' contains. I
reckon a trailing ellipsis added to the contracted text would look
satisfactory and managed to come up with the following routine that uses an
function contractTextToWidth theText,theWidth
put "..." into fld "CTTW"
put the formattedWidth of char 1 to 3 of fld "CTTW" into tWidthA
-- tWidthA = width of trailing ellipsis
repeat with i = length(theText) down to 1
put theText into fld "CTTW"
put the formattedWidth of char 1 to i of fld "CTTW" into tWidthB
-- tWidthB = width of remaining string
if tWidthA+tWidthB <= theWidth then
delete last char of theText
... But I'm thinking there's probably a better way (particularly when lots
of cells are involved - I might end up with a couple of hundred). Any ideas?
More information about the Use-livecode