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
3587
votes
10 answers

Does Python have a string 'contains' substring method?

I'm looking for a string.contains or string.indexof method in Python. I want to do: if not somestring.contains("blah"): continue
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
3384
votes
31 answers

Case insensitive 'Contains(string)'

Is there a way to make the following return true? string title = "ASTRINGTOTEST"; title.Contains("string"); There doesn't seem to be an overload that allows me to set the case sensitivity. Currently I UPPERCASE them both, but that's just silly (by…
Boris Callens
  • 90,659
  • 85
  • 207
  • 305
2657
votes
36 answers

How do I check if a string contains a specific word?

Consider: $a = 'How are you?'; if ($a contains 'are') echo 'true'; Suppose I have the code above, what is the correct way to write the statement if ($a contains 'are')?
Charles Yeung
  • 38,347
  • 30
  • 90
  • 130
1403
votes
18 answers

Determine whether an array contains a value

I need to determine if a value exists in an array. I am using the following function: Array.prototype.contains = function(obj) { var i = this.length; while (i--) { if (this[i] == obj) { return true; } } …
Prasad
  • 58,881
  • 64
  • 151
  • 199
1147
votes
12 answers

How do I check if string contains substring?

I have a shopping cart that displays product options in a dropdown menu and if they select "yes", I want to make some other fields on the page visible. The problem is that the shopping cart also includes the price modifier in the text, which can be…
Jordan Garis
  • 11,489
  • 3
  • 16
  • 4
965
votes
16 answers

SQL SELECT WHERE field contains words

I need a select which would return results like this: SELECT * FROM MyTable WHERE Column1 CONTAINS 'word1 word2 word3' And I need all results, i.e. this includes strings with 'word2 word3 word1' or 'word1 word3 word2' or any other combination of…
Mario
  • 13,941
  • 20
  • 54
  • 110
625
votes
19 answers

Check if multiple strings exist in another string

How can I check if any of the strings in an array exists in another string? For example: a = ['a', 'b', 'c'] s = "a123" if a in s: print("some of the strings found in s") else: print("no strings found in s") How can I replace the if a in s:…
jahmax
  • 8,181
  • 7
  • 26
  • 25
607
votes
6 answers

Is there a short contains function for lists?

Given a list xs and a value item, how can I check whether xs contains item (i.e., if any of the elements of xs is equal to item)? Is there something like xs.contains(item)? For performance considerations, see Fastest way to check if a value exists…
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
461
votes
12 answers

How to check that an element is in a std::set?

How do you check that an element is in a set? Is there a simpler equivalent of the following code: myset.find(x) != myset.end()
fulmicoton
  • 15,502
  • 9
  • 54
  • 74
316
votes
24 answers

How to check if a string contains text from an array of substrings in JavaScript?

Pretty straight forward. In javascript, I need to check if a string contains any substrings held in an array.
PercivalMcGullicuddy
  • 5,263
  • 9
  • 46
  • 65
313
votes
5 answers

Check if item is in an array / list

If I've got an array of strings, can I check to see if a string is in the array without doing a for loop? Specifically, I'm looking for a way to do it within an if statement, so something like this: if [check that item is in array]:
SomeKittens
  • 38,868
  • 19
  • 114
  • 143
289
votes
14 answers

Java List.contains(Object with field value equal to x)

I want to check whether a List contains an object that has a field with a certain value. Now, I could use a loop to go through and check, but I was curious if there was anything more code efficient. Something like; if(list.contains(new…
Rudi Kershaw
  • 12,332
  • 7
  • 52
  • 77
275
votes
5 answers

LIKE vs CONTAINS on SQL Server

Which one of the following queries is faster (LIKE vs CONTAINS)? SELECT * FROM table WHERE Column LIKE '%test%'; or SELECT * FROM table WHERE Contains(Column, "test");
user667429
  • 2,993
  • 2
  • 18
  • 15
274
votes
10 answers

Search for "does-not-contain" on a DataFrame in pandas

I've done some searching and can't figure out how to filter a dataframe by df["col"].str.contains(word) however I'm wondering if there is a way to do the reverse: filter a dataframe by that set's compliment. eg: to the effect…
stites
  • 4,903
  • 5
  • 32
  • 43
216
votes
4 answers

Check if a value exists in ArrayList

How can I check if a value exists in an ArrayList? List lista = new ArrayList(); CurrentAccount conta1 = new CurrentAccount("Alberto Carlos", 1052); CurrentAccount conta2 = new CurrentAccount("Pedro Fonseca",…
daniel__
  • 11,633
  • 15
  • 64
  • 91
1
2 3
99 100