Comparing strings lexicographically

Comparing std::string -s like that will work. However you are comparing string literals. To do the comparison you want either initialize a std::string with them or use strcmp: if(std::string(“aa”) > std::string(“bz”)) cout<<“Yes”; This is the c++ style solution to that. Or alternatively: if(strcmp(“aa”, “bz”) > 0) cout<<“Yes”; EDIT(thanks to Konrad Rudolph’s comment): in fact in … Read more

detect differences between two strings with Javascript

I don’t have a Javascript implementation on hand per se, but you’re doing something for which well-established algorithms exist. Specifically, I believe you’re looking for the “Levenshtein distance” between two strings — i.e. the number of insertions, substitutions and deletions (assuming you are treating a deletion as a change). The wikipedia page for Levenshtein distance … Read more

Text comparison algorithm

Typically this is accomplished by finding the Longest Common Subsequence (commonly called the LCS problem). This is how tools like diff work. Of course, diff is a line-oriented tool, and it sounds like your needs are somewhat different. However, I’m assuming that you’ve already constructed some way to compare words and sentences.

Compare version strings in groovy

This appears to work String mostRecentVersion(List versions) { def sorted = versions.sort(false) { a, b -> List verA = a.tokenize(‘.’) List verB = b.tokenize(‘.’) def commonIndices = Math.min(verA.size(), verB.size()) for (int i = 0; i < commonIndices; ++i) { def numA = verA[i].toInteger() def numB = verB[i].toInteger() if (numA != numB) { return numA <=> … Read more

Extract the difference between two strings in Java

google-diff-match-patch The Diff Match and Patch libraries offer robust algorithms to perform the operations required for synchronizing plain text. Diff: Compare two blocks of plain text and efficiently return a list of differences. Match: Given a search string, find its best fuzzy match in a block of plain text. Weighted for both accuracy and location. … Read more

How to compare two dates along with time in java

Since Date implements Comparable<Date>, it is as easy as: date1.compareTo(date2); As the Comparable contract stipulates, it will return a negative integer/zero/positive integer if date1 is considered less than/the same as/greater than date2 respectively (ie, before/same/after in this case). Note that Date has also .after() and .before() methods which will return booleans instead.