for example, how do i know that the "hello world" string contains three letter l?
+1
A:
var hm:int = 0;
var index:int = 0;
while ((index = your_string.indexOf(your_substring, index)) != -1) {
index++;
hm++;
}
trace('how many: ' + hm);
Awesome Code! This one correctly answers multi-letter substrings. Example: how many times does "lol" occur in "lololol". Some code might incorrectly return 2... or maybe even 1, but this code will correctly return 3.If you want to truely know how many times a string contains a substring, this is it (the original question). If you want to know how many times you encounter (substring) while moving forward through string, you can use a simpler method.
AlReece45
2010-05-01 06:17:21
+1
A:
Easy:
your_string.match( your_substring ).length;
Or cheesy:
your_string.split( your_substring ).length - 1;
drawnonward
2010-05-01 06:08:52