String search

Hey, I am trying to search a string for the number of <BR>'s in it.

 count = 0;
 oInd = 0;
 while (oInd=_root.blah.indexOf("<BR>", oInd+1) != -1) {
  if (oInd == -1) {
   break;
  }
  count++;
 }
 trace(count); 

this is what I am trying but it says that a code is causing flash to run too slowly.

I just don’t know what to do about this.

Try:

my_string = "This<br>is<br>my<br>string<br>!";
n = my_string.split("<br>").length-1;
trace(n);

it just returns 0

Zero?
Hmmm… are you using <br> or <BR>?

nevermind. Thats very clever.

just so you know, the problem with your original script was just a result of order of operations. You need for the oInd var to be defined before the comparison of the result, otherwise it will always be assigned to true or false (depending on the comparaison outcome).

while ( (oInd = _root.blah.indexOf("<br>", oInd+1)) != -1) count++;

… you also need to start oInd at -1, so the initial +1 will make 0.

Thanks for the further explanation sen. :sen: