我想在循环时检查news_text变量是否在文本变量中包含相同的字符串。 news _text可以包含的字符串是:
“也门部长说萨利赫试图破坏过渡http://t.co/aXOQPMzf”
,文本变量的字符串是
“RT @路透社:也门部长说萨利赫试图破坏过渡http://t.co/aXOQPMzf”
for (var i = 0; i < full_array.length; i++) {
var user = full_array[i].user;
var date = full_array[i].date;
var profile_img = full_array[i].profile_img;
var text = full_array[i].text;
var news_user = full_array[i].news_user;
var news_date = full_array[i].news_date;
var news_profile_img = full_array[i].news_profile_img;
var news_text = full_array[i].news_text;
if(text==news_text){
geocode (user,date,profile_img,text,news_user,news_date,news_profile_img,news_text);
}
}
任何有帮助的人?
答案 0 :(得分:0)
鉴于模糊字符串匹配的复杂性,我建议您查看这样的网站 from Google - Yeti Witch。谷歌搜索Soundex和JavaScript还有其他例子。
祝你好运。答案 1 :(得分:0)
只需使用
if (text.indexOf(news_text) > -1) // text contains news_text
geocode(…);
编辑:如果您只需要搜索news_text
的前10个字符,请使用
if (text.indexOf(news_text.substr(0, 10)) > -1) // text contains news_text
geocode(…);