查找以数组AS3开头的字符串

| 我想防止用户使用网络摄像头模拟器,我已经通过使用senocular的功能在AS2中做到了这一点,但是我无法使其在AS3中工作,所以,这是senocular的旧版本,我想若要在AS3中执行相同操作,请尝试使用indexOf但不起作用,我需要至少找到字符串的前4个字符,并将它们与AS3中数组内的项目进行比较!
String.prototype.startsWith = function(str){
        return !this.indexOf(str);
    }
这是我想做的:
var bannedDevices = new Array(\"FakeCam\",\"SplitCam\",\"Phillips Capture Card 7xx\",\"VLC\");

var myDeviceName = \"SplitCam v1.5\";  //\"Splitcam\" in bannedDevices should trigger this;

if (myDeviceName.indexOf(bannedDevices)){
   trace(\"banned device\");
}
谢谢您的帮助 !     
已邀请:
好的,我将以前的答案留给历史。现在,我已经了解了您想要什么:
public function FlashTest() {
    var bannedDevices:Array = new Array(\"FakeCam\",\"SplitCam\",\"Phillips Capture Card 7xx\",\"VLC\");

    var myDeviceName:String = \"SplitCam v1.5\";  //\"Splitcam\" in bannedDevices should trigger this;

    trace(startsWith(myDeviceName, bannedDevices, 4));
}

/**
* @returns An array of strings in pHayStack beginning with pLength first characters of pNeedle
*/
private function startsWith(pNeedle:String, pHayStack:Array, pLength:uint):Array
{
    var result:Array = [];
    for each (var hay:String in pHayStack)
    {
        if (hay.match(\"^\"+pNeedle.substr(0,pLength)))
        {
            result.push(hay);
        }
    }
    return result;
}
    
您的需求不是很清楚...这是一个函数,该函数从以给定字符串开头的数组中返回每个字符串。
public function FlashTest() {
    var hayStack:Array = [\"not this one\", \"still not this one\", \"ok this one is good\", \"a trap ok\", \"okgood too\"];

    trace(startsWith(\"ok\", hayStack));
}

/**
* @returns An array of strings in pHayStack beginning with the given string
*/
private function startsWith(pNeedle:String, pHayStack:Array):Array
{
    var result:Array = [];
    for each (var hay:String in pHayStack)
    {
        if (hay.match(\"^\"+pNeedle))
        {
            result.push(hay);
        }
    }
    return result;
}
    

要回复问题请先登录注册