Please consider this string list:
Afghanistan, Albania, Algeria, El Salvador,
Equatorial, Guinea, Eritrea, Estonia
Ethiopia, Panama, Papua, Paraguay
Peru, Togo, Trinidad & Tobago, Tunisia, Turkey
and I have another list:
tan, ia, Tu
I want all countries that contains tan
or ia
or Tu
. How I can do this without foreach
loop?
thanks
答案 0 :(得分:2)
Try Linq which will perform the loop for you:
var apiKey = 'apikey';
var pageToken = '';
var numOfResult = 0;
var maxResults = 200;
function searchVideo(){
var separator = ",";
$.getJSON('https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&pageToken=' + pageToken + '&playlistId=PLrEnWoR732-BHrPp_Pm8_VleD68f9s14-&key=apikey&callback=?',function(data){
var l = data.items.length;
pageToken = data.nextPageToken;
numOfResult += l;
var itemUrl = '';
for(var i = 0; i < l; i++) {
if( i == 0) {
separator = ',';
}
else {
separator = ',';
}
var videoid = data.items[i].snippet.resourceId.videoId;
var title = data.items[i].snippet.title;
console.log(videoid);
var input_data = "<input type='hidden' value='" + videoid + "' name='videoid[" + i + "]'><input type='hidden' value='" + title + "' name='title[" + i + "]'>";
$("form").append(input_data);
}
if( numOfResult < maxResults) {
searchVideo();
}
});
}
答案 1 :(得分:2)
Try something like that;
library(data.table)
as.data.table(data)[, .SD[any(Age >= 20 & Age < 30)], Household_id]
# Household_id Household_relation Age
# 1: 2 1 27
# 2: 2 2 34
# 3: 4 1 22
# 4: 4 2 23
# 5: 7 2 21
# 6: 7 1 29
# 7: 11 1 31
# 8: 11 2 29
Also, I have ignored the case sensitive. If you want to perform case sensitive use
var listA = new List<string> {"Afghanistan", "England"};
var listB = new List<string> {"afg"};
listA = listA.Where(x => listB.Any(k => x.IndexOf(k, StringComparison.OrdinalIgnoreCase) > -1)).ToList();
instead of x.IndexOf(k, StringComparison.Ordinal)
.
答案 2 :(得分:1)
Try a simple Where statement with checking all the filters inside as so:
<div class="mf-container">
<div class="mf-content">
<div class="row">
<div class="mf-third mf-center">
<img src="img/qualifications/gimp_g.png" class="mf-pic-unique mf-pic-
shadow mf-margin-top" id="gimp" alt="about gimp">
<p id="qGimp" class="mf-off-black-text"> </p>
</div>
<div class="mf-third mf-margin-top">
<p class="mf-center mf-off-black-text">Click on an image to learn more
about each technology</p>
</div>
<div class="mf-third mf-center">
<img src="img/qualifications/inkscape_G.png" class="mf-pic-unique mf-
pic-shadow mf-margin-top" id="inkscape" alt="about inkscape">
<p id="qInkscape" class="mf-off-black-text"> </p>
</div>
</div>
</div>
</div>
Also check it in this fiddle: https://dotnetfiddle.net/PdZvp4