How do I make my string comparison case-insensitive?

The best way is to use str.equalsIgnoreCase(“foo”). It’s optimized specifically for this purpose. You can also convert both strings to upper- or lowercase before comparing them with equals. This is a trick that’s useful to remember for other languages which might not have an equivalent of equalsIgnoreCase. str.toUpperCase().equals(str2.toUpperCase()) If you are using a non-Roman alphabet, … Read more

Type-juggling and (strict) greater/lesser-than comparisons in PHP

PHP’s comparison operators deviate from the computer-scientific definitions in several ways: In order to constitute an equivalence relation == has to be reflexive, symmetric and transitive: PHP’s == operator is not reflexive, i.e. $a == $a is not always true: var_dump(NAN == NAN); // bool(false) Note: The fact that any comparison involving NAN is always … Read more

Why does this string extension method not throw an exception?

You are using yield return. When doing so, the compiler will rewrite your method into a function that returns a generated class that implements a state machine. Broadly speaking, it rewrites locals to fields of that class and each part of your algorithm between the yield return instructions becomes a state. You can check with … Read more

Should __ne__ be implemented as the negation of __eq__?

Python, should I implement __ne__() operator based on __eq__? Short Answer: Don’t implement it, but if you must, use ==, not __eq__ In Python 3, != is the negation of == by default, so you are not even required to write a __ne__, and the documentation is no longer opinionated on writing one. Generally speaking, … Read more

What’s the difference between ScalaTest and Scala Specs unit test frameworks?

Specs and ScalaTest are both good tools with happy users, but they differ in several ways. You will probably want to pick one as your main testing tool in Scala, but need not give up the other because you can use pieces of both. If you like ScalaTest’s FeatureSpec syntax and specs’ Mockito syntax, for … Read more

What is “missing” in the Visual Studio 2008 Express Editions?

The major areas where Visual Studio Express lacks features compared to Visual Studio Professional: No add-ins/macros Some Win32 tools missing No Team Explorer support Limited refactoring support Debugging is much more limited (particularly problematic for server development is no remote debugging) Lack of support for setup projects No report creation tools No Office development support … Read more

Compare Strings Javascript Return %of Likely

Here’s an answer based on Levenshtein distance https://en.wikipedia.org/wiki/Levenshtein_distance function similarity(s1, s2) { var longer = s1; var shorter = s2; if (s1.length < s2.length) { longer = s2; shorter = s1; } var longerLength = longer.length; if (longerLength == 0) { return 1.0; } return (longerLength – editDistance(longer, shorter)) / parseFloat(longerLength); } For calculating edit … Read more

C# vs Java generics [duplicate]

streloksi’s link does a great job of breaking down the differences. The quick and dirty summary though is … In terms of syntax and usage. The syntax is roughly the same between the languages. A few quirks here and there (most notably in constraints). But basically if you can read one, you can likely read/use … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)