string-comparison

Bug in the string comparing of the .NET Framework

自闭症网瘾萝莉.ら 提交于 2019-11-28 17:22:48
问题 It's a requirement for any comparison sort to work that the underlying order operator is transitive and antisymmetric. In .NET, that's not true for some strings: static void CompareBug() { string x = "\u002D\u30A2"; // or just "-ア" if charset allows string y = "\u3042"; // or just "あ" if charset allows Console.WriteLine(x.CompareTo(y)); // positive one Console.WriteLine(y.CompareTo(x)); // positive one Console.WriteLine(StringComparer.InvariantCulture.Compare(x, y)); // positive one Console

Best machine learning technique for matching product strings

人盡茶涼 提交于 2019-11-28 17:03:35
问题 Here's a puzzle... I have two databases of the same 50000+ electronic products and I want to match products in one database to those in the other. However, the product names are not always identical. I've tried using the Levenshtein distance for measuring the string similarity however this hasn't worked. For example, -LG 42CS560 42-Inch 1080p 60Hz LCD HDTV -LG 42 Inch 1080p LCD HDTV These items are the same, yet their product names vary quite a lot. On the other hand... -LG 42 Inch 1080p LCD

If statement checking for NSString equality using ==

馋奶兔 提交于 2019-11-28 14:29:07
I am making a server call in some Objective-c code. If it returns as a @"yes" , it will do an action. For some reason, the // DO ACTION HERE part is never reached. NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; NSString *returnStringResults = returnString; NSString *yesText = @"yes"; if (returnStringResults == yesText) { testLabel.text = @"Success"; // DO ACTION HERE } W Dyson if ([returnStringResults isEqualToString:yesText]) { testLabel

Compare the text of two text fields

大兔子大兔子 提交于 2019-11-28 14:02:39
How do you compare the text in two text fields to see if they are the same, such as in "Password" and "Confirm Password" text fields? if (passwordField == passwordConfirmField) { //they are equal to each other } else { //they are not equal to each other } In Objective-C you should use isEqualToString: , like so: if ([passwordField.text isEqualToString:passwordConfirmField.text]) { //they are equal to each other } else { //they are *not* equal to each other } NSString is a pointer type. When you use == you are actually comparing two memory addresses, not two values. The text properties of your

What is the difference between vbNullString, String.Empty and “”?

╄→尐↘猪︶ㄣ 提交于 2019-11-28 13:53:05
All of these txtUsername.Text <> vbNullString txtUsername.Text <> String.Empty txtUsername.Text <> "" seem to return the same result. So, what's the difference between vbNullString , String.Empty and "" ? vbNullString is a constant, more likely out of VB6, String.Empty and "" are the same, some say that there is a performance difference, but that is not true, it is your choice what you use. To check whether a string is empty you can use If String.IsNullOrEmpty(String) . The advantage is that it will also check for null , because string is a class and because of this a reference type. What's

Difference between C# and VB.Net string comparison

[亡魂溺海] 提交于 2019-11-28 12:37:40
I'm actually trying to answer this question but as that's very involved and unlikely to get a good response quickly, I'm going to try and work out the implementation myself. The fundamental problem seems to be that the C# example I was following doesn't translate directly to VB. When examining a String comparison BinaryExpression in a lambda, VB reports the Expression.Method.DeclaringType to be Microsoft.VisualBasic.CompilerServices.Operators with a method name of CompareString . This is clearly VB-specific. The Expression is just comparing x.Content_Type <> "" and calling ToString on it

Comparing two editTexts in android

五迷三道 提交于 2019-11-28 12:14:26
问题 I am learning android I tried following codeline but it's giving me error please give me suggestions, that how can I compare two edittext 's text. if((edt1.getText().toString() && edt4.getText().toString() && edt7.getText().toString)=="X") 回答1: Here's a solution that doesn't violate the DRY principle: private static boolean allContain(final String value, final EditText... editTexts) { for (EditText editText : editTexts) { final String text = editText.getText().toString(); if (!text.equals

Check if variable starts with 'http'

本秂侑毒 提交于 2019-11-28 11:54:45
I'm sure this is a simple solution, just haven't found exactly what I needed. Using php, i have a variable $source. I wanna check if $source starts with 'http'. if ($source starts with 'http') { $source = "<a href='$source'>$source</a>"; } Thanks! if (strpos($source, 'http') === 0) { $source = "<a href=\"$source\">$source</a>"; } Note I use === , not == because strpos returns boolean false if the string does not contain the match. Zero is falsey in PHP, so a strict equality check is necessary to remove ambiguity. Reference: http://php.net/strpos http://php.net/operators.comparison You want the

Similar UTF-8 strings for autocomplete field

为君一笑 提交于 2019-11-28 11:46:40
Background Users can type in a name and the system should match the text, even if the either the user input or the database field contains accented (UTF-8) characters. This is using the pg_trgm module. Problem The code resembles the following: SELECT t.label FROM the_table t WHERE label % 'fil' ORDER BY similarity( t.label, 'fil' ) DESC When the user types fil , the query matches filbert but not filé powder . (Because of the accented character?) Failed Solution #1 I tried to implement an unaccent function and rewrite the query as: SELECT t.label FROM the_table t WHERE unaccent( label ) %

Why does string.Compare seem to handle accented characters inconsistently?

a 夏天 提交于 2019-11-28 09:51:10
If I execute the following statement: string.Compare("mun", "mün", true, CultureInfo.InvariantCulture) The result is '-1', indicating that 'mun' has a lower numeric value than 'mün'. However, if I execute this statement: string.Compare("Muntelier, Schweiz", "München, Deutschland", true, CultureInfo.InvariantCulture) I get '1', indicating that 'Muntelier, Schewiz' should go last. Is this a bug in the comparison? Or, more likely, is there a rule I should be taking into account when sorting strings containing accented The reason this is an issue is, I'm sorting a list and then doing a manual