Line Count for String (code snippet)


Quick line counting function to compute the approximate number of lines required to show a string in an input box.

The second parameter which is the maximum number of is optional and will default to 9 if not passed.

Requires: None


function linecount(string,maxlines)
  @function linecount
  Works out approximate number of lines to display a text string in an input box.
      string:  string to process mandatory
      maxlines:  maximum height for text box,  defaults to 9 lines if not provided
  maxlines = maxlines or 9
  local intLines = 1
    for strLine in string.gmatch(string.."\n","(.-)\n") do
      intLines = intLines + math.ceil(string.len(strLine)/100)
  return math.min(intLines,maxlines)