Questions tagged [contains]

The "contains" operator/method is used to determine if an entity collection contains an element with a particular property.

The contains operator/method is used to determine whether one (or more) of the entities in an entity collection has a particular property.

3008 questions
59
votes
2 answers

Contains of HashSet in Python

In Java we have HashSet, I need similar structure in Python to use contains like below: A = [1, 2, 3] S = set() S.add(2) for x in A: if S.contains(x): print "Example" Could you please help?
Borys Stepov
  • 711
  • 1
  • 5
  • 4
57
votes
10 answers

how to check if a property value exists in array of objects in swift

I am trying to check if a specific item (value of a property) exists in a array of objects, but could not find out any solution. Please let me know, what i am missing here. class Name { var id : Int var name : String …
Nuibb
  • 1,800
  • 2
  • 22
  • 36
57
votes
4 answers

Opposite of .contains (does not contain)

I have an if statement: if (inventory.contains("bread")) But now I want to check if inventory contains "bread" but does not contain "water". How can I do this?
Tizer1000
  • 894
  • 2
  • 8
  • 19
52
votes
2 answers

R - test if first occurrence of string1 is followed by string2

I have an R string, with the format s = `"[some letters and numbers]_[a number]_[more numbers, letters, punctuation, etc, anything]"` I simply want a way of checking if s contains "_2" in the first position. In other words, after the first _…
StanLe
  • 5,037
  • 9
  • 38
  • 41
51
votes
3 answers

Is there a regex to match a string that contains A but does not contain B

My problem is that I want to check the browserstring with pure regex. Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13 Should match Mozilla/5.0 (Linux; U; Android 2.2.1;…
user1061688
  • 511
  • 1
  • 4
  • 3
50
votes
15 answers

String contains any items in an array (case insensitive)

How can i check if a $string contains any of the items expressed in an array? $string = 'My nAmE is Tom.'; $array = array("name","tom"); if(contains($string,$array)) { // do something to say it contains } Any ideas?
tarnfeld
  • 25,992
  • 41
  • 111
  • 146
49
votes
3 answers

IF a cell contains a string

How can I assign a value to cells if it's neighbour contains a specific string? For example, fields in column A: dog11 cat22 cow11 chick11 duck22 cat11 horse22 cat33 The syntax in column B would…
Csongor
  • 593
  • 1
  • 5
  • 17
48
votes
2 answers

Is it possible to use .contains() in a switch statement?

This is just a simple example of what I'm trying to do: switch (window.location.href.contains('')) { case "google": searchWithGoogle(); break; case "yahoo": searchWithYahoo(); break; default: …
RayB
  • 2,096
  • 3
  • 24
  • 42
45
votes
10 answers

VB.NET - If string contains "value1" or "value2"

I'm wondering how I can check if a string contains either "value1" or "value2"? I tried this: If strMyString.Contains("Something") Then End if This works, but this doesn't: If strMyString.Contains("Something") or ("Something2") Then End if This…
Kenny Bones
  • 5,017
  • 36
  • 111
  • 174
44
votes
10 answers

Javascript - check if div contains a word?

How can I check if a div contains a certain word? var divs= document.getElementsByTagName('div'); for (var i = 0, len = divs.length; i < len; ++i) { if (divs[i].text = '*word*'){ //do somthing } } doesn't work.
user1104092
43
votes
7 answers

Using contains() in LINQ to SQL

I'm trying to implement a very basic keyword search in an application using linq-to-sql. My search terms are in an array of strings, each array item being one word, and I would like to find the rows that contain the search terms. I don't mind if…
a_m0d
  • 12,034
  • 15
  • 57
  • 79
38
votes
3 answers

ArrayList's custom Contains method

I have some object class A { private Long id; private String name; public boolean equals(Long v) { return this.id.equals(v); } } and ArrayList of these objects. What I want is to be able to check if that list contains some object by…
nKognito
  • 6,297
  • 17
  • 77
  • 138
38
votes
3 answers

What is the Big-O of String.contains() in Java?

I'm working on a project, and need to optimize the running time. Is String.contains() runtime the same as TreeSet.contains(), which is O(logN)? The reason I'm asking is I'm building a TreeMap>, where Songs contain a String of…
Jason
  • 11,263
  • 21
  • 87
  • 181
38
votes
4 answers

List.contains() fails while .equals() works

I have an ArrayList of Test objects, which use a string as the equivalency check. I want to be able to use List.contains() to check whether or not the list contains an object that uses a certain string. Simply: Test a = new Test("a"); a.equals("a");…
idlackage
  • 2,715
  • 8
  • 31
  • 52
38
votes
3 answers

LINQ: Entity string field contains any of an array of strings

I want to get a collection of Product entities where the product.Description property contains any of the words in a string array. It would look something like this (result would be any product which had the word "mustard OR "pickles" OR "relish"…
Steve Macdonald
  • 1,745
  • 2
  • 20
  • 34