flash:我怎么知道一个字符串包含子串的次数?

时间:2010-05-01 05:23:48

标签: flash

例如,我如何知道“hello world”字符串包含三个字母l?

2 个答案:

答案 0 :(得分:1)

var hm:int = 0;
var index:int = 0;

while ((index = your_string.indexOf(your_substring, index)) != -1) {
    index++;
    hm++;
}

trace('how many: ' + hm);

答案 1 :(得分:1)

易:

your_string.match( your_substring ).length;

或俗气:

your_string.split( your_substring ).length - 1;