contains

Check if a string exists in an array case insensitively

China☆狼群 提交于 2019-11-29 01:02:59
Declaration: let listArray = ["kashif"] let word = "kashif" then this contains(listArray, word) Returns true but if declaration is: let word = "Kashif" then it returns false because comparison is case sensitive. How to make this comparison case insensitive? you can use word.lowercaseString to convert the string to all lowercase characters let list = ["kashif"] let word = "Kashif" if contains(list, {$0.caseInsensitiveCompare(word) == NSComparisonResult.OrderedSame}) { println(true) // true } Xcode 7.3.1 • Swift 2.2.1 if list.contains({$0.caseInsensitiveCompare(word) == .OrderedSame}) { print

Pandas: Check if row exists with certain values

巧了我就是萌 提交于 2019-11-29 00:04:35
问题 I have a two dimensional (or more) pandas DataFrame like this: >>> import pandas as pd >>> df = pd.DataFrame([[0,1],[2,3],[4,5]], columns=['A', 'B']) >>> df A B 0 0 1 1 2 3 2 4 5 Now suppose I have a numpy array like np.array([2,3]) and want to check if there is any row in df that matches with the contents of my array. Here the answer should obviously true but eg. np.array([1,2]) should return false as there is no row with both 1 in column A and 2 in column B. Sure this is easy but don't see

String contains another two strings

99封情书 提交于 2019-11-28 23:26:41
Is it possible to have the contain function find if the string contains 2 words or more? This is what I'm trying to do: string d = "You hit someone for 50 damage"; string a = "damage"; string b = "someone"; string c = "you"; if(d.Contains(b + a)) { Console.WriteLine(" " + d); Console.ReadLine(); } When I run this, the console window just shuts down really fast without showing anything. And another question: if I for one want to add how much damage is done, what would be the easiest way to get that number and get it into a TryParse ? You would be better off just calling Contains twice or making

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

眉间皱痕 提交于 2019-11-28 20:06:55
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 init(id:Int, name:String){ self.id = id self.name = name } } var objarray = [Name]() objarray.append(Name(id: 1, name: "Nuibb")) objarray.append(Name(id: 2, name: "Smith")) objarray.append(Name(id: 3, name: "Pollock")) objarray.append(Name(id: 4, name: "James")) objarray.append(Name(id: 5, name: "Farni")) objarray.append(Name(id: 6, name: "Kuni")) if contains(objarray["id"], 1) {

Fastest way to check if a List<String> contains a unique String

五迷三道 提交于 2019-11-28 18:31:15
Basically I have about 1,000,000 strings, for each request I have to check if a String belongs to the list or not. I'm worried about the performance, so what's the best method? ArrayList ? Hash? krock Your best bet is to use a HashSet and check if a string exists in the set via the contains() method. HashSets are built for fast access via the use of Object methods hashCode() and equals() . The Javadoc for HashSet states: This class offers constant time performance for the basic operations (add, remove, contains and size), HashSet stores objects in hash buckets which is to say that the value

Finding Points contained in a Path in Android

会有一股神秘感。 提交于 2019-11-28 17:15:09
问题 Is there a reason that they decided not to add the contains method (for Path) in Android? I'm wanting to know what points I have in a Path and hoped it was easier than seen here: How can I tell if a closed path contains a given point? Would it be better for me to create an ArrayList and add the integers into the array? (I only check the points once in a control statement) Ie. if(myPath.contains(x,y) So far my options are: Using a Region Using an ArrayList Extending the Class Your suggestion I

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

你离开我真会死。 提交于 2019-11-28 17:00:08
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; en-us; Nexus One Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 should not match my tried solution is: /?((?<=Android)(?:[^])*?(?=Mobile))/i but it matches exactly wrong. You use look ahead assertions to check if a string contains a word or not. If you want to assure that the string contains "Android" at some

xpath: find a node that has a given attribute whose value contains a string

大憨熊 提交于 2019-11-28 16:34:38
问题 Is there an xpath way to find a node that has a given attribute whose value contains a given string? For example I have an xml document and want to find a node where the address attribute contains the string Downing , so that I could find the following node: <person name="blair" address="10 Downing St. London"/> 回答1: select="//*[contains(@address,'Downing')]" 来源: https://stackoverflow.com/questions/614797/xpath-find-a-node-that-has-a-given-attribute-whose-value-contains-a-string

search for “does-not-contain” on a dataframe in pandas

允我心安 提交于 2019-11-28 15:56:23
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 of !(df["col"].str.contains(word)) . Can this be done through a DataFrame method? Andy Hayden You can use the invert (~) operator (which acts like a not for boolean data): new_df = df[~df["col"].str.contains(word)] , where new_df is the copy returned by RHS. contains also accepts a regular expression... If the above throws a ValueError, the reason is likely because you

How to check if a table contains an element in Lua?

人走茶凉 提交于 2019-11-28 15:27:07
问题 Is there a method for checking if a table contains a value ? I have my own (naive) function, but I was wondering if something "official" exists for that ? Or something more efficient... function table.contains(table, element) for _, value in pairs(table) do if value == element then return true end end return false end By the way, the main reason I'm using this functions is to use tables as sets, ie with no duplicate elements. Is there something else I could use ? 回答1: You can put the values