Counting Line Breaks in htmlText

Is there any way to count line breaks within htmlText? It doesn’t look like using

indexOf("<br>");

will work because the renderer has already created the textfield display by the time this code would run. So there wouldn’t be any tags to find, just rendered text.

Flash really falls on its *** when it comes to this… storing the HTML in a variable beforehand and querying that is probably the best way.



var str:String = "Here is some <br/> test text <br/> to check for <br/> linebreaks";
test.htmlText = str;

trace(test.htmlText.indexOf("<br/>")); // -1 = not present
trace(test.text.indexOf("
")); // -1 = not present
trace(str.indexOf("<br/>")); // 13 = present

You could also do:

escape(t.text).indexOf("%0D");

To count the breaks, I would use the String.split method and use the length of the returned array minus 1:

escape(t.text).split("%0D").length - 1

Thanks all for the replies.

[QUOTE=TheCanadian;2347013]You could also do:

escape(t.text).indexOf("%0D");

To count the breaks, I would use the String.split method and use the length of the returned array minus 1:

escape(t.text).split("%0D").length - 1

[/QUOTE]

Good stuff, I knew there had to be a way to get at it.

Glad to help :hoser: