flash: how do i know how many times a string contains the substring?
for example, how do i know that the "hello world" string contains three letter l开发者_StackOverflow社区?
var hm:int = 0;
var index:int = 0;
while ((index = your_string.indexOf(your_substring, index)) != -1) {
index++;
hm++;
}
trace('how many: ' + hm);
Easy:
your_string.match( your_substring ).length;
Or cheesy:
your_string.split( your_substring ).length - 1;
精彩评论