How to compare string with specific part of array item?

Related searches

I have an array arr[] of string type with array-items as follows:

arr[0]= "2/13/2019|202"
arr[1]= "2/14/2019|197"
arr[2]= "2/15/2019|101"
arr[4]= "2/16/2019|271"
arr[5]= "2/17/2019|199"

I want to get an array-item that matches my string "2/15/2019" so I can get "2/15/2019|101". in short, I just want to compare my string with the array-item string till "|" and rest strong will not be considered for comparison. how can I get it?

You could use Where and StartWith

var results = arr.Where(x => x.StartsWith("2/15/2019")); 

Additional Resources

Enumerable.Where Method

Filters a sequence of values based on a predicate.

String.StartsWith Method

Determines whether the beginning of this string instance matches a specified string.

Check If String Array Contains a Value In Java, The simplest way to find out if a String Array contains a certain value is to "Bike" ; boolean found = false; for (String element:myStringArray ) { if� The ISNUMBER function handles the array of numbers and errors returned by FIND and converts the numbers to TRUE and anything else to FALSE. A double unary (--) coerces the logical values into ones and zeros. SUMPRODUCT sums the array of 1's and 0's and returns the count of cells that contain the specified text as part of their contents.

Compare strings - MATLAB strcmp, The input arguments can be any combination of string arrays, character vectors, and Compare each element in two cell arrays of character vectors. Input text, with each input specified as a character vector, a character array, a cell array of� In this post, we will check if two String arrays are equal to one another or not. The two String arrays are considered equal if both arrays have same length, and contains same elements in the same order. 1. Comparing Single Dimensional Arrays. Naive solution would be to write our own method for checking equality of String array.

Use where and contains

           string getdata = "2/15/2019";
            string[] arr = new string[5];
            arr[0] = "2/13/2019|202";
            arr[1] = "2/14/2019|197";
            arr[2] = "2/15/2019|101";
            arr[3] = "2/16/2019|271";
            arr[4] = "2/17/2019|199";

            var op = arr.Where(a => a.Contains(getdata)).FirstOrDefault();

String \ Language (API) \ Processing 3+, Comparing String objects, see reference below. searching strings, extracting parts of strings, and for converting an entire string uppercase and lowercase. charAt(), Returns the character at the specified index data, byte[] or char[]: either an array of bytes to be decoded into characters, or an array of� A string you want to find across all items in the array. include Optional. If True the Filter function will return a subset array that contain the match string. If False the Filter function will return a subset array that do not contain the match string. The default value is True. compare Optional. The type of comparison to be performed.

JavaScript Array every(): Determining If All Array Elements Pass a Test, Sometimes, you need to test whether every element of an array satisfies a specified condition. Typically, you use a for loop to iterate all elements and check each� In this article, we'll look at different ways to search an array for a specified value. We'll also compare how these perform using JMH (the Java Microbenchmark Harness) to determine which method works best.

String/Array Comparison (The GNU C Library), Unlike most comparison operations in C, the string comparison functions return a nonzero The sign of the value indicates the relative ordering of the first part of the strings that are wide character is a1 is smaller or larger than the corresponding wide character in a2 . For example, given a structure type definition like:. Here, we declared an array of arrays with size 4. We initialize each element with a String Array that represents a pair of husband and wife names. To access a specific item, we need two index values. For example, to output "Robert", the code should be: System.out.println( coupleArray[2][0] ); And to access "Josephine", the code should be:

Note: if the ArrayList objects you want to compare contains objects of a custom class, then the class must override equals and hashCode methods as given below. Additionally, if you sort ArrayList using sort method, the custom class also needs to implement Comparable interface and define the compareTo method.

Comments
  • use contains() method
  • var results = arr.Where(x => x.StartsWith("2/15/2019"));
  • just need to remove?
  • @devSS If you use ?. before Split, you wont get Null Reference exceptions if there is no element in the array that contains that string. Try a search with string that doesnt match. ?. ensures there is always a value to run split on without exceptions.