comparison

C# Check if a List is a part of another List [duplicate]

邮差的信 提交于 2020-01-01 11:45:00
问题 This question already has answers here : Check whether an array is a subset of another (8 answers) Closed 6 years ago . I have two lists as follows var query1 = from enrollments in db.Enrollments where enrollments.studentID == studentID && enrollments.result >= 50 && enrollments.enrolled == false select enrollments.subjectID; var query2 = from prerequisites in db.Prerequisites where prerequisites.subjectID == subjectID select prerequisites.prerequisiteID; Now I want to make sure that all the

How can I ignore accents when comparing strings in Perl?

纵饮孤独 提交于 2020-01-01 08:51:10
问题 I have this quiz application where I match what people type with the right answer. For now, what I do is basically that : if ($input =~ /$answer/i) { print "you won"; } It's nice, as if the answer is "fish" the user can type "a fish" and be counted a good answer. The problem I'm facing is that, well, my users as I are french, and I'd like to be able to accept, say, a user typing "taton", and the answer being "tâton". So, what I could do, is : use POSIX qw(locale_h); use locale; setlocale(LC

How can I ignore accents when comparing strings in Perl?

孤街醉人 提交于 2020-01-01 08:51:09
问题 I have this quiz application where I match what people type with the right answer. For now, what I do is basically that : if ($input =~ /$answer/i) { print "you won"; } It's nice, as if the answer is "fish" the user can type "a fish" and be counted a good answer. The problem I'm facing is that, well, my users as I are french, and I'd like to be able to accept, say, a user typing "taton", and the answer being "tâton". So, what I could do, is : use POSIX qw(locale_h); use locale; setlocale(LC

diff files comparing only first n characters of each line

折月煮酒 提交于 2020-01-01 07:52:48
问题 I have got 2 files. Let us call them md5s1.txt and md5s2.txt. Both contain the output of a find -type f -print0 | xargs -0 md5sum | sort > md5s.txt command in different directories. Many files were renamed, but the content stayed the same. Hence, they should have the same md5sum. I want to generate a diff like diff md5s1.txt md5s2.txt but it should compare only the first 32 characters of each line, i.e. only the md5sum, not the filename. Lines with equal md5sum should be considered equal. The

What to do with null fields in compare()?

青春壹個敷衍的年華 提交于 2020-01-01 07:32:11
问题 In Java, I use a class in which some fields can be null . For example: class Foo { String bar; //.... } I want to write a BarComparator for this class, private static class BarComparator implements Comparator<Foo> { public int compare( final Foo o1, final Foo o2 ) { // Implementation goes here } } Is there a standard way to deal with the fact that any of o1 , o2 , o1.bar , o2.bar can be null , without writing lots of nested if ... else ? Cheers! 回答1: I guess you could wrap the call to the

What to do with null fields in compare()?

不羁的心 提交于 2020-01-01 07:32:00
问题 In Java, I use a class in which some fields can be null . For example: class Foo { String bar; //.... } I want to write a BarComparator for this class, private static class BarComparator implements Comparator<Foo> { public int compare( final Foo o1, final Foo o2 ) { // Implementation goes here } } Is there a standard way to deal with the fact that any of o1 , o2 , o1.bar , o2.bar can be null , without writing lots of nested if ... else ? Cheers! 回答1: I guess you could wrap the call to the

How to find rectangle of difference between two images

◇◆丶佛笑我妖孽 提交于 2020-01-01 05:40:06
问题 I have two images the same size. What is the best way to find the rectangle in which they differ. Obviously I could go through the image 4 times in different directions, but i'm wondering if there's an easier way. Example: 回答1: I don't think there is an easier way. In fact doing this will just be a (very) few lines of code, so unless you find a library that does that for you directly you won't find a shorter way. 回答2: A naive approach would be to start at the origin, and work line by line,

Comparing a string to an array in objective-C

拥有回忆 提交于 2020-01-01 05:35:50
问题 here's a very basic question, that I'm sure you will be able to answer quickly. Please don't laugh at my ignorance. I have a string, that I want to compare to an array of strings. Only if the string is not part of the array, I want to perform an operation. I tried the following code, that doesn't work. I do understand why, but I just can't think of a way to do it correctly. Please help me out of my misery. Thanks in advance Sjakelien -(void) findRedundant: (NSString *) aString { #define ALPHA

Java 8: More efficient way of comparing lists of different types?

人走茶凉 提交于 2019-12-31 21:12:53
问题 In a unit test, I want to verify that two lists contain the same elements. The list to test is build of a list of Person objects, where one field of type String is extracted. The other list contains String literals. One often finds the following code snippet to accomplish this task (see this answer): List<Person> people = getPeopleFromDatabasePseudoMethod(); List<String> expectedValues = Arrays.asList("john", "joe", "bill"); assertTrue(people.stream().map(person -> person.getName()).collect

Java 8: More efficient way of comparing lists of different types?

筅森魡賤 提交于 2019-12-31 21:12:36
问题 In a unit test, I want to verify that two lists contain the same elements. The list to test is build of a list of Person objects, where one field of type String is extracted. The other list contains String literals. One often finds the following code snippet to accomplish this task (see this answer): List<Person> people = getPeopleFromDatabasePseudoMethod(); List<String> expectedValues = Arrays.asList("john", "joe", "bill"); assertTrue(people.stream().map(person -> person.getName()).collect