AS2 检查字符串是否包含特定顺序的字母

AS2 check if string contains letters in specific order

我正在尝试在 Action Script 2 中编写一段代码,用于检查字符串是否包含特定字符。 例如: 字符串 1 - "wqeeqwejqwqwqaretrtviyiiyia"; 值得注意的是,这里的隐藏词是java。我正在尝试制作一个类似它的代码: 如果字符串按顺序包含字母 "j,a,v,a" 那么做 ------

有什么帮助吗?

不确定 AS2 语法,但类似这样的语法应该有效:

function containsWord(originalString:String, word:String):Boolean
{
    var lettersFound:Number = 0;

    for(i=0; i<myString.length; i++)
    {
        // check next letter in the originalString
        var currentLetter:String = originalString.charAt(i);

        // increase the lettersFound if the currentLetter is the next letter in our word. This also means that next time we will check for the next letter in the word
        if (currentLetter == word.charAt(lettersFound))
        {
            lettersFound++;
        }
    }

    // return true if the lettersFound equals the length of our word (meaning we've found all letters)
    return lettersFound == word.length;
}

var stringContainsWord:Boolean = containsWord("wqeeqwejqwqwqaretrtviyiiyia", "java");
trace(stringContainsWord);