contain

Checking if long is in array

▼魔方 西西 提交于 2019-12-14 02:14:35
问题 I need to make sure that a certain long value isn't in an array. But for some reason, this isn't working... !d.toString().contains(sq.toString()); I am sure I am getting something really backwards... but I can't figure out what! 回答1: Try !Arrays.asList(d).contains(sq); 回答2: Look at the static methods in java.util.Arrays. Your array will need to be sorted for the binarySearch() to work. 来源: https://stackoverflow.com/questions/5010044/checking-if-long-is-in-array

Cakephp contain and belongsTo hasMany conditions

十年热恋 提交于 2019-12-13 07:37:48
问题 From the CakePHP manual: Let's say you had a belongsTo relationship between Posts and Authors. Let's say you wanted to find all the posts that contained a certain keyword ("magic") or were created in the past two weeks, but you want to restrict your search to posts written by Bob: array ( "Author.name" => "Bob", "OR" => array ( "Post.title LIKE" => "%magic%", "Post.created >" => date('Y-m-d', strtotime("-2 weeks")) ) ) However, its not working for me. I've got Scrapes belongsTo Vargroup, and

Look if an array has an specified object

和自甴很熟 提交于 2019-12-12 01:48:55
问题 I have an array composed of an X number of 2DPoints, and my goal is to do a boolean operation that could check if that array has the specified 2DPoint. Something like this: Point2D.Double arrayPoints[] = new Point2D.Double[numberOfPoints]; Point2D.Double pointPVariable = new Point2D.Double(positionXVariable,positionYVariable); arrayPoints[variableNumber] = pointPVariable; if(arrayPoints has the Point2D(2.45,6.52)){ do this } How can I do that boolean operation?? Thank you very much! 回答1:

See if String Contains An Element in an Array

百般思念 提交于 2019-12-11 00:17:44
问题 I am trying to go through an array of Operators to see if one of the operators is located in the String. For example: String[] OPERATORS = { "<", "<=", ... }; String line = "a <= b < c "; How would I go about going through a loop that checks to see if an operator is in the string? Also, say my method found that "<" is located in the string at " < = " However, I am looking for the actual string " <= ". How would I go about accounting for that? 回答1: I would use a regex instead of having array

CakePHP 3. Containable select

自古美人都是妖i 提交于 2019-12-10 17:33:35
问题 I have a many to many relation where TrainingPrograms can contain many Exercises. They are a linked via the linktable ExercisesTrainingPrograms. I want to select certain fields from my exercises: $trainingPrograms = $this->TrainingPrograms->find() ->contain(['Exercises' => function ($q) { return $q ->select(['id','name','description']); } ]) ->select(['id','name','description']) ->where(['user_id' => $this->Auth->user('id')]); The result i get looks like so: "trainingPrograms": [ { "id": 1,

Fastest way to check does string contain any word from list

亡梦爱人 提交于 2019-12-10 14:23:01
问题 I have Python application. There is list of 450 prohibited phrases. There is message got from user. I want to check, does this message contain any of this prohibited pharases. What is the fastest way to do that? Currently I have this code: message = "sometext" lista = ["a","b","c"] isContaining = false for a, member in enumerate(lista): if message.contains(lista[a]): isContaining = true break Is there any faster way to do that? I need to handle message (max 500 chars) in less than 1 second.

Java: How to check if a string is a part of any LinkedList element?

会有一股神秘感。 提交于 2019-12-08 06:09:08
问题 Okay so I have a LinkedList, and I have a String. I want to check if the String is contained within any of the LinkedList elements. For example: String a = "apple"; String listelement = "a bunch of apples"; LinkedList list = new LinkedList(); list.add(listelement); if(list.containsany(a){ System.out.println("Hooray!"); } Would result in printing "Hooray!" Obviously list.containsany isn't a real LinkedList method, I'm just using it for this purpose. So how can I simulate my example? Thanks 回答1

Checking if string is only letters and spaces - Python

拥有回忆 提交于 2019-12-07 03:54:02
问题 Trying to get python to return that a string contains ONLY alphabetic letters AND spaces string = input("Enter a string: ") if all(x.isalpha() and x.isspace() for x in string): print("Only alphabetical letters and spaces: yes") else: print("Only alphabetical letters and spaces: no") I've been trying please and it comes up as Only alphabetical letters and spaces: no I've used or instead of and , but that only satisfies one condition. I need both conditions satisfied. That is the sentence must

Checking if string is only letters and spaces - Python

五迷三道 提交于 2019-12-05 08:21:14
Trying to get python to return that a string contains ONLY alphabetic letters AND spaces string = input("Enter a string: ") if all(x.isalpha() and x.isspace() for x in string): print("Only alphabetical letters and spaces: yes") else: print("Only alphabetical letters and spaces: no") I've been trying please and it comes up as Only alphabetical letters and spaces: no I've used or instead of and , but that only satisfies one condition. I need both conditions satisfied. That is the sentence must contain only letters and only spaces but must have at least one of each kind. It must not contain any

Find contains class name in multiple classes

我怕爱的太早我们不能终老 提交于 2019-12-04 19:08:58
I want to get the id in class like... <div class="main demo id_111 test"></div> <div class="main demo test id_222 test demo"></div> <div class="id_3 main demo test test demo"></div> Result must be 111 , 222 and 3 So I code like this var id = $(".main").attr("class"); var id = id.split("id_"); var id = id[1].split(" "); var id = id[0]; $("body").append(id); But someone know better coding than mine ? Playground : http://jsfiddle.net/UHyaD/ You can use a regex : var id = $(".main").attr("class").match(/id_(\d*)/)[1]; JSfiddle : http://jsfiddle.net/scaillerie/UHyaD/1/ You can use match function: