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
}
}