compare

Compare two NSArrays and return number of differences

南楼画角 提交于 2019-11-30 09:18:40
How can I take two NSArrays, compare them, then return the number of differences, preferably the number of different objects, for example: Array 1: one two three Array 2: two four one I would like that to return "1" You can do this by using an intermediate NSMutableArray : NSArray *array1 = [NSArray arrayWithObjects:@"One", @"Two", @"Three", nil]; NSArray *array2 = [NSArray arrayWithObjects:@"Two", @"Four", @"One", nil]; NSMutableArray *intermediate = [NSMutableArray arrayWithArray:array1]; [intermediate removeObjectsInArray:array2]; NSUInteger difference = [intermediate count]; With that way,

How to add spaces between number and word in a string in Java?

时间秒杀一切 提交于 2019-11-30 09:05:41
问题 i have a lot of string which contains also number like : LOD140IXAL COMP 1X240GG I would like to put whitespace between numbers and word if there isn't. the number could be every where in the string. 回答1: One way to do this is using regular expressions. Replacing the following monster with a single space should do the trick: "(?<=[A-Za-z])(?=[0-9])|(?<=[0-9])(?=[A-Za-z])" When applied to your example ( LOD140IXAL COMP 1X240GG ), it produces LODIXAL COMP 1 X 240 MG . In a nutshell, the regex

Compare XML ignoring order of child elements

╄→гoц情女王★ 提交于 2019-11-30 08:55:37
问题 Does anybody know of a tool that will compare two XML documents. Belay that mocking… there’s more. I need something that will make sure each node in file 1 is also in file 2 regardless of order. I thought XML Spy would do it with the Ignore Order of Child Nodes option but it didn’t. The following would be considered the same: <Node> <Child name="Alpha"/> <Child name="Beta"/> <Child name="Charlie"/> </Node> <Node> <Child name="Beta"/> <Child name="Charlie"/> <Child name="Alpha"/> </Node> 回答1:

Comparing Two objects using Assert.AreEqual()

强颜欢笑 提交于 2019-11-30 08:07:36
I 'm writing test cases for the first time in visual studio c# i have a method that returns a list of objects and i want to compare it with another list of objects by using the Assert.AreEqual() method. I tried doing this but the assertion fails even if the two objects are identical. I wanted to know if this method, the two parameters are comparing references or the content of the object, Do I have to overload the == operator to make this work? anouar.bagari If you are using NUnit this is what the documentation says Starting with version 2.2, special provision is also made for comparing single

How to compare multidimensional arrays in C# ?

此生再无相见时 提交于 2019-11-30 08:04:32
How to compare multidimensional arrays? Just true/false. double[,] data1 = new double[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } }; double[,] data2 = new double[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } }; //bool compare = data1.SequenceEqual(data2); Is there way to compare 2d arrays like 1d array ? data1.SequenceEqual(data2); I have to compare every second, so easiest way will be great. Thanks a lot. user287107 A multidimensional array can be used in linq as one dimensional enumerable. You just need to check also for the length of all dimensions. This snippet should be enough: var equal =

Javascript: Comparing to null - !== vs !=

我怕爱的太早我们不能终老 提交于 2019-11-30 06:23:36
Ok, so I installed Linter on my Sublime editor while working on my node.js app. One of the things that it caught said that I should always use !== to compare an object to null (I usually use != ). So I changed it...but then I noticed that the !== wasn't working. I have this scenario: var x = null; if (x !== null) console.log('x is not equal to null'); When I use the !== the console printed that line even though it was obviously not true. When I switched it back to != it behaved normally. So my question is, why is linter telling me to use !== if it doesn't do what I want it to... I know I am

How to compare just the date part and not the time of two Dates?

可紊 提交于 2019-11-30 05:59:44
I want to compare just the date part (and Not the time) of two VB.NET Date objects. Is there a way to do that? Jon Skeet Just take the date part of each via the Date property and compare the two: date1.Date.CompareTo(date2.Date) Or: If date1.Date < date2.Date Then Compare the DateTime.Date properties. You could also use TimeSpan Dim ts As TimeSpan ts = dt1 - dt2 ts.Days will now have the difference of the two dates as whole days. Wavare Santosh Change the txt1 date to format dd/mm/yyyy using myDateTime.ToShortDateString() so that both the dates will be in same format. then : if (DateTime

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

戏子无情 提交于 2019-11-30 05:36:30
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 fine. Additionally what to be done, if i would like to compare each value of two dictionaries and only update d2 into d1 if values in d1 are empty/None/''? [EDIT] Question: When updating d2 into d1, when the same key exists, I would like to only maintain the numerical value (either from d1 or d2) instead of empty value. If both values are empty, then no

How to compare mp3 programmatically

前提是你 提交于 2019-11-30 04:07:39
I like to be able to compare mp3’s programmatically. The problem I don’t know by what. Header? Histogram? channels? Does anyone have experience with this subject? I wrote my master's thesis on audio fingerprinting. The thesis lists a few open source solutions to the problem of comparing what the music sounds like, and provides performance comparisons between them. Might be overkill, but there are some really decent applications out there. If you only want to compare by tagged data, the standard to look into is ID3 . There are basically two versions, the first is very simple (ID3v1) and

Compare images to find differences

一笑奈何 提交于 2019-11-30 03:43:44
问题 Task: I have a camera mounted on the end of our assembly line, which captures images of produced items. Let's for example say, that we produce tickets (with some text and pictures on them). So every produced ticket is photographed and saved to disk as image. Now I would like to check these saved images for anomalies (i.e. compare them to an image (a template), which is OK). So if there is a problem with a ticket on our assembly line (missing picture, a stain,...), my application should find