Tutorial by Examples: contains

var numbers = new[] {1,2,3,4,5}; Console.WriteLine(numbers.Contains(3)); //True Console.WriteLine(numbers.Contains(34)); //False
var re = /[a-z]+/; if (re.test("foo")) { console.log("Match exists."); } The test method performs a search to see if a regular expression matches a string. The regular expression [a-z]+ will search for one or more lowercase letters. Since the pattern matches the string,...
git reset <filePath>
To allow the use of in for custom classes the class must either provide the magic method __contains__ or, failing that, an __iter__-method. Suppose you have a class containing a list of lists: class ListList: def __init__(self, value): self.value = value # Create a set of al...
var favoriteColors: Set = ["Red", "Blue", "Green"] //favoriteColors = {"Blue", "Green", "Red"} You can use the contains(_:) method to check whether a set contains a value. It will return true if the set contains that value. if favorite...
This example shows the usage of the ILGenerator by generating code that makes use of already existing and new created members as well as basic Exception handling. The following code emits a DynamicAssembly that contains an equivalent to this c# code: public static class UnixTimeHelper { priva...
Letters 3.0 let letters = CharacterSet.letters let phrase = "Test case" let range = phrase.rangeOfCharacter(from: letters) // range will be nil if no letters is found if let test = range { print("letters found") } else { print("letters not found") }...
This query returns all cones with a chocolate scoop and a vanilla scoop. VANILLA, CHOCOLATE, MINT, STRAWBERRY = 1, 2, 3, 4 # constants for flavors choco_vanilla_cones = IceCream.objects.filter(scoops__contains=[CHOCOLATE, VANILLA]) Don't forget to import the IceCream model from your models.py ...
Managed resources are resources that the runtime's garbage collector is aware and under control of. There are many classes available in the BCL, for example, such as a SqlConnection that is a wrapper class for an unmanaged resource. These classes already implement the IDisposable interface -- it's u...
This query selects all books with any rating less than three. bad_books = Books.objects.filter(ratings_range__contains=(1, 3))
Pass a dict object to field_name__contains as a keyword argument. Catalog.objects.filter(titles__contains={ 'Pro Git': 'Scott Chacon and Ben Straub'}) Equivalent to the SQL operator `@>`.
public static class ArrayHelpers { public static bool Contains<T>(this T[] array, T[] candidate) { if (IsEmptyLocate(array, candidate)) return false; if (candidate.Length > array.Length) return false; for (int a = 0; a <...
A common problem is having a collection of items that all need to meet a certain criteria. In the example below we have collected two items for a diet plan and we want to check that the diet doesn't contain any unhealthy food. // First we create a collection $diet = collect([ ['name' => ...
XML <Data> <BioLight> <name>Firefly</name> <model>Insect</model> </BioLight> <ArtificialLight> <name>Fire</name> <model>Natural element</model> <source>flint<...
Const baseString As String = "Foo Bar" Dim containsBar As Boolean 'Check if baseString contains "bar" (case insensitive) containsBar = InStr(1, baseString, "bar", vbTextCompare) > 0 'containsBar = True 'Check if baseString contains bar (case insensitive) co...
Python makes it extremely intuitive to check if a string contains a given substring. Just use the in operator: >>> "foo" in "foo.baz.bar" True Note: testing an empty string will always result in True: >>> "" in "test" True
Enums contains only constants and can be compared directly with ==. So, only reference check is needed, no need to use .equals method. Moreover, if .equals used incorrectly, may raise the NullPointerException while that's not the case with == check. enum Day { GOOD, AVERAGE, WORST; } publi...
To check if a Dictionary has an specifique key, you can call the method ContainsKey(TKey) and provide the key of TKey type. The method returns a bool value when the key exists on the dictionary. For sample: var dictionary = new Dictionary<string, Customer>() { {"F1", new Custom...
MSDN: Determines whether a sequence contains a specified element by using a specified IEqualityComparer<T> List<int> numbers = new List<int> { 1, 2, 3, 4, 5 }; var result1 = numbers.Contains(4); // true var result2 = numbers.Contains(8); // false List<int> secondN...
Apart from primitives, the Explicit Layout structs (Unions) in C#, can also contain other Structs. As long as a field is a Value type and not a Reference, it can be contained in a Union: using System; using System.Runtime.InteropServices; // The struct needs to be annotated as "Explici...

Page 1 of 2