How to get number of text lines

edited July 2016 in How To...

Hello,

Im using the following code:

text(textString,0,0,width,height);

With this short piece of code, the program prints the text which I have set to the textString. If the string width is longer than my applet width, it automatically 'splits' the text and prints the rest of the text on the next 'line'.

But how can I get the number of lines the programm uses to show this text? As an example...

Hello, this is a

test in Processing

should give the number 2 (there are 2 lines).

I hope you understand me... Regards, Daantje

Answers

  • That's difficult

    Short answer: You can't

    Maybe you can calc an approx value with width of the box and using length() of the string and function textWidth

    But not reliable....

    You could write your own function ....

Sign In or Register to comment.