# Counting Line Breaks in htmlText

**URL:** <https://forum.kirupa.com/t/counting-line-breaks-in-htmltext/264012>\
**Category:** flash\
**Created:** [June 22, 2008, 2:36am UTC](https://forum.kirupa.com/t/counting-line-breaks-in-htmltext/264012 "2008-06-22T02:36:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pherank](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pherank](https://forum.kirupa.com/u/Pherank)\
**Post date:** [June 22, 2008, 2:36am UTC](https://forum.kirupa.com/t/counting-line-breaks-in-htmltext/264012/1 "2008-06-22T02:36:26Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![McGuffin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mcguffin/32/408_2.png) [@McGuffin](https://forum.kirupa.com/u/McGuffin)\
**Post date:** [June 22, 2008, 2:58am UTC](https://forum.kirupa.com/t/counting-line-breaks-in-htmltext/264012/2 "2008-06-22T02:58:46Z")

</div>

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.

```auto

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

```

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [June 22, 2008, 6:38am UTC](https://forum.kirupa.com/t/counting-line-breaks-in-htmltext/264012/3 "2008-06-22T06:38:32Z")

</div>

You could also do:

```auto
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:

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

```

---

<div class="post-metadata">

**Author:** ![Pherank](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pherank](https://forum.kirupa.com/u/Pherank)\
**Post date:** [June 22, 2008, 10:04pm UTC](https://forum.kirupa.com/t/counting-line-breaks-in-htmltext/264012/4 "2008-06-22T22:04:21Z")

</div>

Thanks all for the replies.

---

<div class="post-metadata">

**Author:** ![McGuffin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mcguffin/32/408_2.png) [@McGuffin](https://forum.kirupa.com/u/McGuffin)\
**Post date:** [June 22, 2008, 10:25pm UTC](https://forum.kirupa.com/t/counting-line-breaks-in-htmltext/264012/5 "2008-06-22T22:25:57Z")

</div>

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

```auto
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:

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

```

[/QUOTE]

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

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [June 22, 2008, 10:32pm UTC](https://forum.kirupa.com/t/counting-line-breaks-in-htmltext/264012/6 "2008-06-22T22:32:31Z")

</div>

Glad to help :hoser:
