0
我正在为Android游戏Word小吃在android上创建一个程序。它会比较文件中搜索到的字符串和单词(还不是来自文件,只是用字符串进行测试)(请参阅规则)。在线"Script Error: Cannot read property 'length' of null"
:但是,无论我做什么,我仍然得到错误JavaScript匹配函数返回null
if((from_file.match(new RegExp(from_file[i], "g") || [])).length != (searched.match(new RegExp(from_file[i], "g") || [])).length)
在功能compare_words(from_file, searched)
。我正在使用(string.match(new RegExp(searched_str, "g") || [])).length
来查找堆栈溢出时已经显示的字符串中出现的次数。但我仍然在犯这个错误。有谁能够帮助我?比你。 :d
function OnStart()
{
lay = app.CreateLayout("linear", "");
var from_file = "dedo";
var searched = "odod";
if(compare_words(from_file, searched) == true)
{
txt = app.CreateText(from_file + ": true");
txt.SetTextSize(32);
lay.AddChild(txt);
}
app.AddLayout(lay);
}
function compare_words(from_file, searched)
{
if(from_file.length == searched.length)
{
var b = 0;
for(i = 0; i < from_file.length; i++)
{
if((from_file.match(new RegExp(from_file[i], "g") || [])).length != (searched.match(new RegExp(from_file[i], "g") || [])).length)
{
b = 1;
break;
}
}
if(b == 0)
{
return true
}
else
{
return false
}
}
else
{
return false
}
}