Counting the number of 'return/line break' characters in a string?


#1

I’m trying to figure out how to count the number of line breaks in a string. Someone put this brilliant concept in another post the count the number of occurrences of a character:

[[LVAR1.text.length - LVAR1.text.replace (“a”,"").length]]

but I don’t know how to use ‘line break’ instead of ‘a’ in the above. I’m trying to count the number of hard linebreaks so I can resize the height of a widget to accomodate both the number of characters + the number of hard line breaks.

Thanks!


#2

Just replace “a” with “\n” which is a regular expression for “newline” or “end of line” character.

You can also use the local variable, LVAR1, to point to the text of a widget directly, instead of the widget itself, so the algorithm can be [[LVAR1.length - LVAR1.replace ("\n,"").length]]

Here is a demo: count chars and lines.rp (50.5 KB)


#3

Of course!!! It’s amazing the things you forget…

Thanks again!


closed #4

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.