String Comparison in Java

Leading from answers from @Bozho and @aioobe, lexicographic comparisons are similar to the ordering that one might find in a dictionary. The Java String class provides the .compareTo () method in order to lexicographically compare Strings. It is used like this “apple”.compareTo (“banana”). The return of this method is an int which can be interpreted … Read more

Version number comparison in Python

How about using Python’s distutils.version.StrictVersion? >>> from distutils.version import StrictVersion >>> StrictVersion(‘10.4.10’) > StrictVersion(‘10.4.9’) True So for your cmp function: >>> cmp = lambda x, y: StrictVersion(x).__cmp__(y) >>> cmp(“10.4.10”, “10.4.11”) -1 If you want to compare version numbers that are more complex distutils.version.LooseVersion will be more useful, however be sure to only compare the same … Read more

Why does PHP convert a string with the letter E into a number?

“608E-4234” is the float number format, so they will cast into number when they compares. 608E-4234 and 272E-3063 will both be float(0) because they are too small. For == in php, If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the … Read more

How to compare Unicode characters that “look alike”?

Because it is really different symbols even they look the same, first is the actual letter and has char code = 956 (0x3BC) and the second is the micro sign and has 181 (0xB5). References: Unicode Character ‘GREEK SMALL LETTER MU’ (U+03BC) Unicode Character ‘MICRO SIGN’ (U+00B5) So if you want to compare them and … Read more

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