comparison

Why doesn't my string equality test for a single character work?

How does one compare single character strings in Perl? Right now, I'm tryin to use "eq": print "Word: " . $_[0] . "\n"; print "N for noun, V for verb, and any other key if the word falls into neither category.\n"; $category = <STDIN>; print "category is...." . $category . "\n"; if ($category eq "N") { print "N\n"; push (@nouns...

Not able to compare range.length to an integer

I am developing an app in iPhone I am using an NSRange object in my code. if (range.length == 0) { do something } When I print the the value of range.length on the console it writes 0. Which means my if condition holds valid. But it never enter inside the loop to do something. Any clue what I might be doing wrong? Thanks...

Fastest way to compare a string with an array of strings in C#2.0

What is the fastest way to compare a string with an array of strings in C#2.0 ...

I wanna have an Extension method "Equals" between 2 byte arrays.

Hi! I am doing some byte[] comparisons. I tried == but this is just like the base Equals, which: byte[] a = {1,2,3}; byte[] b = {1,2,3}; bool equals = a == b; //false equals = a.Equals(b); //false I tried to add an extension method, but since the overloaded base class' Equals takes the same arguments, it goes to the base method rath...

hi i need help with c# array problem

hi im preparing for an exam and i am new to c# i am having problem with a question that i have what i am having problem is that i need to find out how many times the number greater than or less than one appears in the array for example if i have an array {1,1,1,2,3,-18,45,1} here numbers that are greater than or less than one appears...

Java: If vs. Switch

I have a piece of code with a) which I replaced with b) purely for legibility ... a) if ( WORD[ INDEX ] == 'A' ) branch = BRANCH.A; /* B through to Y */ if ( WORD[ INDEX ] == 'Z' ) branch = BRANCH.Z; b) switch ( WORD[ INDEX ] ) { case 'A' : branch = BRANCH.A; break; /* B through to Y */ case 'Z' : branch = BRANCH.Z; brea...

python decimal comparison

python decimal comparison >>> from decimal import Decimal >>> Decimal('1.0') > 2.0 True I was expecting it to convert 2.0 correctly, but after reading thru PEP 327 I understand there were some reason for not implictly converting float to Decimal, but shouldn't in that case it should raise TypeError as it does in this case >>> Decimal...

Object comparison in JavaScript

What is the best way to compare Objects in JavaScript? Example: var user1 = {name : "nerd", org: "dev"}; var user2 = {name : "nerd", org: "dev"}; var eq = user1 == user2; alert(eq); // gives false I know that "Two objects are equal if they refer to the exact same Object", but is there a way to check it another way?? Using this way w...

Equality testing in Javascript

just trying to test for equality in this piece of code, but getting a fail. <input type="text" name="dave_blah"/> <input type="text" name="dave_bleh"/> I then access the name values of each of these inputs and assign them to two variables, name1 and name2. I then extract the first part of the name,delimited by a "_". var oldName = n...

unique integer/long hash key generation over strings for faster compairson

I'm curious how others have solved this problem, and what problems might lurk behind the naive solution: I have a system which processes stock market data. There are tens of thousands of symbols, with associated prices/sizes, flowing into the system at the rate of several thousand every millisecond. One of the basic operations that ne...

What advantages/disadvantages do MSTest and NUnit have compared to each other?

Since Microsoft created MSTest, I've been using it for unit testing. I never really used NUnit, and I just didn't like the need to have yet another tool installed on my dev box. I've only used the basic features of MSTest so far, and they have satisfied my needs, and I don't really know anything about NUnit. Could someone list out some ...

LINQ | How do I perform Date Comparison in a Linq Query?

Please help. I am trying to figure out how to use DATE or DATETIME for comparison in a linq query. Example: If I wanted all Employee names for those who started before today, I would do something like this in SQL: SQL ------ Select EmployeeNameColumn From EmployeeTable WHERE StartDateColumn.Date <= GETDATE() //Today SQL ------ But w...

What is the best way to compare two entity framework entities?

Hi All, I want to know the most efficient way of comparing two entities of the same type. One entity is created from an xml file by hand ( ie new instance and manually set properties) and the other is retvied from my object context. I want to know if the property values are the same in each instance. My first thoughts are to generate...

Resources for learning a new language quickly?

The title may seem slightly self-contradictory, and I accept that you can't really learn a language quickly. However, an experienced programmer that already has knowledge of a few languagues and different styles (functional, OO, imperative etc.) often wants to get started quickly. I've seen a few websites doing effective "translations" i...

NSComparisonResult is not showing proper result

I need to compair current time with two time rang, its work fine in every case but when I check "12:00 PM" to "01:30 PM", it give me wrong value. NSComparisonResult timeStart=[@"01:02 PM" compare:@"12:00 PM"]; NSComparisonResult timeEnd=[@"01:02 PM" compare:@"01:30 PM"]; both timeStart and timeEnd are -1? where timeStart is bigger ...

Is there a more efficient way to reconcile large data sets?

I've been tasked with reconciling two big data sets (two big lists of transactions). Basically i extract the relevant fields from the two data sources into two files of the same format, then compare the files to find any records that are in A but not in B, or vice versa, and report on them. I wrote a blog entry on my best efforts achievi...

Is dotNet decimal type vulnerable for the binary comparison error?

One error I stumble upon every few month is this one: double x = 19.08; double y = 2.01; double result = 21.09; if (x + y == result) { MessageBox.Show("x equals y"); } else { MessageBox.Show("that shouldn't happen!"); // <-- this code fires ...

Efficency of Comparisons in C++? ( abs(X)>1 vs abs(x) != 0)

I know- Premature optimization. But I've got code that's supposed to find out if a position is changed vs a cached position. Current code is: if(abs(newpos-oldpos) > 1){ ..... } Is it more efficient to use the following? if(abs(newpos-oldpos) != 0){ .... } Why or why not? I'm currently debating it my head which is more re...

Compare two Arrays Javascript - Associative

Hi, I have searched on here for a quality method to compare associative arrays in javascript. The only decent solution I have found is the PHP.JS project which has some comparative array functions. The only problem is that these functions consider the first array as the key to the second. In my situation at least both arrays do not alway...

Why do the '<' and 'lt' operators return different results in Perl?

I am just learning Perl's comparison operators. I tried the below code :- $foo=291; $bar=30; if ($foo < $bar) { print "$foo is less than $bar (first)\n"; } if ($foo lt $bar) { print "$foo is less than $bar (second)\n"; } The output is 291 is less than 30 (second). Does this mean the lt operator always converts th...