Comparing a string with the empty string (Java)

s1 == “” is not reliable as it tests reference equality not object equality (and String isn’t strictly canonical). s1.equals(“”) is better but can suffer from null pointer exceptions. Better yet is: “”.equals(s1) No null pointer exceptions. EDIT: Ok, the point was asked about canonical form. This article defines it as: Suppose we have some … Read more

Bug in the string comparing of the .NET Framework

If correct sorting is so important in your problem, just use ordinal string comparison instead of culture-sensitive. Only this one guarantees transitive and antisymmetric comparing you want. What MSDN says: Specifying the StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase value in a method call signifies a non-linguistic comparison in which the features of natural languages are ignored. Methods that … Read more

What is difference between different string compare methods [duplicate]

Ripped from msdn string.Equals Determines whether this instance and a specified object, which must also be a String object, have the same value. string.Compare Compares two specified String objects and returns an integer that indicates their relative position in the sort order. string.CompareTo Compares this instance with a specified object or String and returns an … Read more

Should I compare a std::string to “string” or “string”s?

Neither. If you want to be clever, compare to “string”sv, which returns a std::string_view. While comparing against a literal like “string” does not result in any allocation-overhead, it’s treated as a null terminated string, with all the concomittant disadvantages: No tolerance for embedded nulls, and users must heed the null terminator. “string”s does an allocation, … Read more

C++ Compare char array with string

Use strcmp() to compare the contents of strings: if (strcmp(var1, “dev”) == 0) { } Explanation: in C, a string is a pointer to a memory location which contains bytes. Comparing a char* to a char* using the equality operator won’t work as expected, because you are comparing the memory locations of the strings rather … Read more

Could string comparisons really differ based on culture when the string is guaranteed not to change?

Absolutely. Per MSDN (http://msdn.microsoft.com/en-us/library/d93tkzah.aspx), This method performs a word (case-sensitive and culture-sensitive) search using the current culture. So you may get different results if you run it under a different culture (via regional and language settings in Control Panel). In this particular case, you probably won’t have a problem, but throw an i in the … Read more

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