contains

Check if element is in the list (contains)

僤鯓⒐⒋嵵緔 提交于 2019-12-03 04:08:39
问题 I've got a list of elements, say, integers and I want to check if my variable (another integer) is one of the elements from the list. In python I'd do: my_list = [1,2,3,4] # elements my_var = 3 # my variable my_var in my_list # returns boolean How to do that in C++? I thought of using std::list , but I can find no find method in it. I can see such method in std::set structure. More deeply, the problem is that my program is given some unique ids (a list, a set, whatever) and I iterate over a

how to find and return objects in java hashset

一曲冷凌霜 提交于 2019-12-03 03:24:23
According to the HashSet javadoc, HashSet.contains only returns a boolean. How can I "find" an object in a hashSet and modify it (it's not a primitive data type)? I see that HashTable has a get() method, but I would prefer to use the set. You can remove an element and add a different one. Modifying an object while it is in a hash set is a recipe for disaster (if the modification changes the hash value or equality behavior). To quote the source of the stock Sun java.util.HashSet: public class HashSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, java.io.Serializable { static final

How can I tell if a VARCHAR variable contains a substring?

柔情痞子 提交于 2019-12-03 02:55:23
问题 I thought it was CONTAINS , but that's not working for me. I'm looking to do this: IF CONTAINS(@stringVar, 'thisstring') ... I have to run one select or another, depending on whether that variable contains a string and I can't figure out how to get it to work. All the examples I'm seeing are using columns in the contains. Thanks in advance. 回答1: The standard SQL way is to use like: where @stringVar like '%thisstring%' That is in a query statement. You can also do this in TSQL: if @stringVar

IF a cell contains a string

末鹿安然 提交于 2019-12-03 00:54:46
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 be: =IF(SEARCH("cat",A1),"cat",IF(SEARCH("22",A1),"22","none")) It always picks up the first TRUE cell, but drops when the value is not true. shipr SEARCH does not return 0 if there is no match, it returns #VALUE! . So you have to wrap calls to SEARCH with IFERROR . For example... =IF(IFERROR(SEARCH("cat", A1), 0), "cat", "none") or =IF(IFERROR(SEARCH("cat",A1),0),"cat",IF(IFERROR(SEARCH("22",A1),0),

Javascript - check if div contains a word?

吃可爱长大的小学妹 提交于 2019-12-02 22:04:52
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. use the indexOf function if(divs[i].innerHTML.indexOf("word") !== -1) { // something } Use includes() : node.textContent.includes('Some text'); if (document.getElementById('divId').innerHTML.indexOf("word") != -1) { } Try the String.indexOf() function: if (divs[i].text.indexOf('word') != -1) { You have to use a comparison operator not assign a variable. if (divs[i].text == '*word*'){ I

Syntax error near 'of' in the full-text search condition 'control of'

早过忘川 提交于 2019-12-02 22:04:33
I have the following WHERE clause: WHERE (@Keywords IS NULL OR (CONTAINS((p.Title, p.Area, p.[Message]), @Keywords)) ) If @Keywords = 'control' , then the query executes successfully and filters my records If @Keywords = 'control of' , then I get the following error: Syntax error near 'of' in the full-text search condition 'control of'. Why is this and what can I do to resolve the issue? The main reason I'm using this method over using LIKE condition is so that I can search multiple words. Oleg Dok Enclose the keywords in double quotes if you want to search exactly for control of SET @Keywords

Why does the Contains() operator degrade Entity Framework' Linq queries?

不问归期 提交于 2019-12-02 21:21:00
问题 I read here that in entity framework if you perform contains operation it reduces performance: Contains is converted to "WHERE IN" in SQL which cause performance degrades" Now I have nearly 10 tables having 10 column and while fetching records I use Contains for nearly 8 columns. My question is above true? If yes what is the alternate to that? 回答1: Yes Contains() will degrade performance heavily. So You can try below mentioned solution. We were able to solve the EF Contains problem by adding

Check if element is in the list (contains)

若如初见. 提交于 2019-12-02 17:28:19
I've got a list of elements, say, integers and I want to check if my variable (another integer) is one of the elements from the list. In python I'd do: my_list = [1,2,3,4] # elements my_var = 3 # my variable my_var in my_list # returns boolean How to do that in C++? I thought of using std::list , but I can find no find method in it. I can see such method in std::set structure. More deeply, the problem is that my program is given some unique ids (a list, a set, whatever) and I iterate over a long list of input data (ids) and check if they are included in the list (boolean value returned for

How can I tell if a VARCHAR variable contains a substring?

柔情痞子 提交于 2019-12-02 16:29:46
I thought it was CONTAINS , but that's not working for me. I'm looking to do this: IF CONTAINS(@stringVar, 'thisstring') ... I have to run one select or another, depending on whether that variable contains a string and I can't figure out how to get it to work. All the examples I'm seeing are using columns in the contains. Thanks in advance. The standard SQL way is to use like: where @stringVar like '%thisstring%' That is in a query statement. You can also do this in TSQL: if @stringVar like '%thisstring%' Instead of LIKE (which does work as other commenters have suggested), you can

Issue with “contains” hashset method (Java)

…衆ロ難τιáo~ 提交于 2019-12-02 13:32:02
问题 The following code is not giving me the result I'm expecting: public static void main (String[] args) { Set<Pair> objPair = new LinkedHashSet<Pair>(); objPair.add(new Pair(1, 0)); System.out.println("Does the pair (1, 0) exists already? "+objPair.contains(new Pair(1, 0))); } private static class Pair { private int source; private int target; public Pair(int source, int target) { this.source = source; this.target = target; } } The result will be: Does the pair (1, 0) exists already? false I