$wrap
From Scriptwiki
Returns Nth line in text wrapped to the specified width in pixels.
$wrap(text, font, size, width, [word,] N)
If the optional word parameter is 1, text is wrapped at whole words (which is the default).
You can specify 0 for N to return the total number of wrapped lines.
Example
$wrap(The quick brown fox jumped over the lazy dog., Arial, 12, 100, 0)
Returns "3" for the total number of lines.
$wrap(The quick brown fox jumped over the lazy dog., Arial, 12, 100, 3)
Returns "the lazy dog."
$wrap(The quick brown fox jumped over the lazy dog., Arial, 12, 100, 0, 2)
Returns "ox jumped over th"