开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜