string-comparison

Understanding NSString comparison

会有一股神秘感。 提交于 2019-11-26 00:16:09
问题 Both the following comparisons evaluate to true: 1) @\"foo\" == @\"foo\"; 2) NSString *myString1 = @\"foo\"; NSString *myString2 = @\"foo\"; myString1 == myString2; However, there are definitely times where two NSString s cannot be compared using the equality operator, and [myString1 isEqualToString:myString2] is required instead. Can someone shed some light on this? 回答1: The reason why == works is because of pointer comparison. When you define a constant NSString using @"" , the compiler

How can I make SQL case sensitive string comparison on MySQL?

拥有回忆 提交于 2019-11-26 00:04:14
问题 I have a function that returns five characters with mixed case. If I do a query on this string it will return the value regardless of case. How can I make MySQL string queries case sensitive? 回答1: http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html The default character set and collation are latin1 and latin1_swedish_ci, so nonbinary string comparisons are case insensitive by default. This means that if you search with col_name LIKE 'a%', you get all column values that start with A

Similarity String Comparison in Java

∥☆過路亽.° 提交于 2019-11-25 23:53:27
问题 I want to compare several strings to each other, and find the ones that are the most similar. I was wondering if there is any library, method or best practice that would return me which strings are more similar to other strings. For example: \"The quick fox jumped\" -> \"The fox jumped\" \"The quick fox jumped\" -> \"The fox\" This comparison would return that the first is more similar than the second. I guess I need some method such as: double similarityIndex(String s1, String s2) Is there

How do I compare version numbers in Python?

别等时光非礼了梦想. 提交于 2019-11-25 23:46:19
问题 I am walking a directory that contains eggs to add those eggs to the sys.path . If there are two versions of the same .egg in the directory, I want to add only the latest one. I have a regular expression r\"^(?P<eggName>\\w+)-(?P<eggVersion>[\\d\\.]+)-.+\\.egg$ to extract the name and version from the filename. The problem is comparing the version number, which is a string like 2.3.1 . Since I\'m comparing strings, 2 sorts above 10, but that\'s not correct for versions. >>> \"2.3.1\" > \"10.1

Getting the closest string match

ぐ巨炮叔叔 提交于 2019-11-25 23:38:27
问题 I need a way to compare multiple strings to a test string and return the string that closely resembles it: TEST STRING: THE BROWN FOX JUMPED OVER THE RED COW CHOICE A : THE RED COW JUMPED OVER THE GREEN CHICKEN CHOICE B : THE RED COW JUMPED OVER THE RED COW CHOICE C : THE RED FOX JUMPED OVER THE BROWN COW (If I did this correctly) The closest string to the \"TEST STRING\" should be \"CHOICE C\". What is the easiest way to do this? I plan on implementing this into multiple languages including

Check whether a string is not null and not empty

匆匆过客 提交于 2019-11-25 22:59:14
问题 How can I check whether a string is not null and not empty? public void doStuff(String str) { if (str != null && str != \"**here I want to check the \'str\' is empty or not**\") { /* handle empty string */ } /* ... */ } 回答1: What about isEmpty() ? if(str != null && !str.isEmpty()) Be sure to use the parts of && in this order, because java will not proceed to evaluate the second part if the first part of && fails, thus ensuring you will not get a null pointer exception from str.isEmpty() if

How can I do a case insensitive string comparison?

こ雲淡風輕ζ 提交于 2019-11-25 21:46:14
How can I make the line below case insensitive? drUser["Enrolled"] = (enrolledUsers.FindIndex(x => x.Username == (string)drUser["Username"]) != -1); I was given some advice earlier today that suggested I use: x.Username.Equals((string)drUser["Username"], StringComparison.OrdinalIgnoreCase))); the trouble is I can't get this to work, I've tried the line below, this compiles but returns the wrong results, it returns enrolled users as unenrolled and unenrolled users as enrolled. drUser["Enrolled"] = (enrolledUsers.FindIndex(x => x.Username.Equals((string)drUser["Username"], StringComparison