How to compare strings

In C++ the std::string class implements the comparison operators, so you can perform the comparison using == just as you would expect: if (string == “add”) { … } When used properly, operator overloading is an excellent C++ feature.

How to compare Go errors

Declaring an error, and comparing it with ‘==‘ (as in err == myPkg.ErrTokenExpired) is no longer the best practice with Go 1.13 (Q3 2019) The release notes mentions: Go 1.13 contains support for error wrapping, as first proposed in the Error Values proposal and discussed on the associated issue. An error e can wrap another … Read more

Sort an array in the same order of another array

Use indexOf() to get the position of each element in the reference array, and use that in your comparison function. var reference_array = [“ryan”, “corbin”, “dan”, “steven”, “bob”]; var array = [“bob”, “dan”, “steven”, “corbin”]; array.sort(function(a, b) { return reference_array.indexOf(a) – reference_array.indexOf(b); }); console.log(array); // [“corbin”, “dan”, “steven”, “bob”] Searching the reference array every time … Read more

Efficient way to compare version strings in Java [duplicate]

Requires commons-lang3-3.8.1.jar for string operations. /** * Compares two version strings. * * Use this instead of String.compareTo() for a non-lexicographical * comparison that works for version strings. e.g. “1.10”.compareTo(“1.6”). * * @param v1 a string of alpha numerals separated by decimal points. * @param v2 a string of alpha numerals separated by decimal points. … Read more

Select rows from one data.frame that are not present in a second data.frame

sqldf provides a nice solution a1 <- data.frame(a = 1:5, b=letters[1:5]) a2 <- data.frame(a = 1:3, b=letters[1:3]) require(sqldf) a1NotIna2 <- sqldf(‘SELECT * FROM a1 EXCEPT SELECT * FROM a2’) And the rows which are in both data frames: a1Ina2 <- sqldf(‘SELECT * FROM a1 INTERSECT SELECT * FROM a2’) The new version of dplyr has … Read more