Questions tagged [compare]

The analysis required to assess the differences and similarities between two or more entities.

This tag is used to classify a question as one dealing with the comparison of at least two entities. The essence of questions that are tagged should boil down to one of the following questions:

  1. How do I control when the compiler/interpreter thinks that two entities are equal? How do I control when the compiler/interpreter thinks that two entities are unequal?
  2. How do I control when the compiler/interpreter thinks that one entity is bigger than the other?
  3. How do I control when the compiler/interpreter thinks that one entity is smaller than the other?

Note that in some languages, it is possible to define asymmetric inequalities. That is, cases in which a<b does not mean that b<a. This is why in python, there exist separate functions for __gt__ (greater than) and __lt__ (less than), etc

9183 questions
64
votes
13 answers

How would you compare two XML Documents?

As part of the base class for some extensive unit testing, I am writing a helper function which recursively compares the nodes of one XmlDocument object to another in C# (.NET). Some requirements of this: The first document is the source, e.g.…
Neil C. Obremski
  • 15,617
  • 20
  • 62
  • 90
62
votes
10 answers

Efficient way to compare version strings in Java

Possible Duplicate: How do you compare two version Strings in Java? I've 2 strings which contains version information as shown below: str1 = "1.2" str2 = "1.1.2" Now, can any one tell me the efficient way to compare these versions inside strings…
Mike
  • 6,732
  • 24
  • 61
  • 81
61
votes
8 answers

In Python, is there a concise way of comparing whether the contents of two text files are the same?

I don't care what the differences are. I just want to know whether the contents are different.
Corey Trager
  • 21,253
  • 16
  • 78
  • 121
60
votes
14 answers

Checking for duplicate strings in JavaScript array

I have JS array with strings, for example: var strArray = [ "q", "w", "w", "e", "i", "u", "r"]; I need to compare for duplicate strings inside array, and if duplicate string exists, there should be alert box pointing to that string. I was trying to…
Bengall
  • 717
  • 1
  • 5
  • 12
59
votes
10 answers

Linq where clause compare only date value without time value

var _My_ResetSet_Array = _DB .tbl_MyTable .Where(x => x.Active == true && x.DateTimeValueColumn <= DateTime.Now) .Select(x => x); Upper query is working correct. But I want to check only date value only. But upper query check…
Frank Myat Thu
  • 4,172
  • 9
  • 61
  • 112
58
votes
7 answers

Difference between period and comma when concatenating with echo versus return?

I just found that this will work: echo $value , " continue"; but this does not: return $value , " continue"; While "." works in both. What is the difference between a period and a comma here?
omg
  • 123,990
  • 135
  • 275
  • 341
56
votes
4 answers

Why is one string greater than the other when comparing strings in JavaScript?

I see this code from a book: var a = "one"; var b = "four"; a>b; // will return true but it doesn't mention why "one" is bigger than "four". I tried c = "a" and it is smaller than a and b. I want to know how JavaScript compares these strings.
patriot7
  • 563
  • 1
  • 4
  • 5
56
votes
4 answers

How can I use in_array if the needle is an array?

I have 2 arrays, the value will be loaded from database, below is an example: $arr1 = array(1,2,3); $arr2 = array(1,2,3,4,5,6,7); What I want to do is to check if all the values in $arr1 exist in $arr2. The above example should be a TRUE…
Donny Kurnia
  • 5,062
  • 5
  • 32
  • 47
55
votes
8 answers

Python: Dictionary merge by updating but not overwriting if value exists

If I have 2 dicts as follows: d1 = {('unit1','test1'):2,('unit1','test2'):4} d2 = {('unit1','test1'):2,('unit1','test2'):''} In order to 'merge' them: z = dict(d1.items() + d2.items()) z = {('unit1','test1'):2,('unit1','test2'):''} Works…
siva
  • 1,813
  • 4
  • 19
  • 33
54
votes
6 answers

Java. Ignore accents when comparing strings

The problem it's easy. Is there any function in JAVA to compare two Strings and return true ignoring the accented chars? ie String x = "Joao"; String y = "João"; return that are equal. Thanks
framara
  • 2,563
  • 5
  • 24
  • 32
54
votes
15 answers

In Perl, is there a built in way to compare two arrays for equality?

I have two arrays of strings that I would like to compare for equality: my @array1 = ("part1", "part2", "part3", "part4"); my @array2 = ("part1", "PART2", "part3", "part4"); Is there a built-in way to compare arrays like there is for scalars? I…
Bill
  • 13,485
  • 4
  • 38
  • 54
53
votes
4 answers

Compare if two dataframe objects in R are equal?

How do I check if two objects, e.g. dataframes, are value equal in R? By value equal, I mean the value of each row of each column of one dataframe is equal to the value of the corresponding row and column in the second dataframe.
mindless.panda
  • 3,806
  • 3
  • 32
  • 56
52
votes
4 answers

How to tell if a date is between two other dates?

I have the following codes: if date in (start, end): print 'in between' else: print 'No!' date, start and end are all variables with the format of 1/1. What should I do to have it print out the right result? i tried date as 10/2,…
widget
  • 797
  • 3
  • 10
  • 20
51
votes
8 answers

Comparing Class Types in Java

I want to compare the class type in Java. I thought I could do this: class MyObject_1 {} class MyObject_2 extends MyObject_1 {} public boolean function(MyObject_1 obj) { if(obj.getClass() == MyObject_2.class) System.out.println("true"); } I…
Carven
  • 12,832
  • 24
  • 97
  • 139
48
votes
9 answers

Comparing text files with Junit

I am comparing text files in junit using: public static void assertReaders(BufferedReader expected, BufferedReader actual) throws IOException { String line; while ((line = expected.readLine()) != null) { assertEquals(line,…
jon077
  • 10,069
  • 11
  • 37
  • 35