string-comparison

String StartsWith() issue with Danish text

霸气de小男生 提交于 2019-12-20 02:12:27
问题 Can anyone explain this behaviour? var culture = new CultureInfo("da-DK"); Thread.CurrentThread.CurrentCulture = culture; "daab".StartsWith("da"); //false I know that it can be fixed by specifying StringComparison.InvariantCulture . But I'm just confused by the behavior. I also know that "aA" and "AA" are not considered the same in a Danish case-insensitive comparision, see http://msdn.microsoft.com/en-us/library/xk2wykcz.aspx. Which explains this String.Compare("aA", "AA", new CultureInfo(

String Comparison exception within Entity Framework FirstOrDefault

独自空忆成欢 提交于 2019-12-19 19:03:52
问题 I'm querying a table using Entity Framework. The first bit of code was what I wrote, the second bit was what ReSharper suggested I refactor it too. The first one gracefully returns null as it should if the key doesn't exist, but the second throws an exception. This was attempted with 0-1 records in the table (all of the columns are marked as NOT NULL) Code that works: context.brandlink.FirstOrDefault(x => x.ManufacturerKey.ToLower() == manufacturerKey.ToLower()); and code that doesn't work:

String Comparison exception within Entity Framework FirstOrDefault

寵の児 提交于 2019-12-19 19:03:12
问题 I'm querying a table using Entity Framework. The first bit of code was what I wrote, the second bit was what ReSharper suggested I refactor it too. The first one gracefully returns null as it should if the key doesn't exist, but the second throws an exception. This was attempted with 0-1 records in the table (all of the columns are marked as NOT NULL) Code that works: context.brandlink.FirstOrDefault(x => x.ManufacturerKey.ToLower() == manufacturerKey.ToLower()); and code that doesn't work:

Elegant way of converting between StringComparison and StringComparer?

允我心安 提交于 2019-12-19 16:54:23
问题 Some .NET methods use StringComparison as parameter, some use StringComparer (often in form of IComparer). The difference is clear. Is there some elegant way how to get StringComparison from StringComparer or vice versa? I can always write simple method which uses Case statement, but perhaps there is already something present in .NET what I am overlooking. 回答1: Going from StringComparison to StringComparer is simple - just create a Dictionary<StringComparison, StringComparer> : var map = new

Elegant way of converting between StringComparison and StringComparer?

扶醉桌前 提交于 2019-12-19 16:54:11
问题 Some .NET methods use StringComparison as parameter, some use StringComparer (often in form of IComparer). The difference is clear. Is there some elegant way how to get StringComparison from StringComparer or vice versa? I can always write simple method which uses Case statement, but perhaps there is already something present in .NET what I am overlooking. 回答1: Going from StringComparison to StringComparer is simple - just create a Dictionary<StringComparison, StringComparer> : var map = new

Why PHP casts two numerical strings to numbers before [loosely] comparing them?

点点圈 提交于 2019-12-19 13:04:05
问题 I browsed through several similar questions, but they all only state the fact: If ... comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically. Okay, I got it. It explains what is going on when '00001' == '1' returns TRUE . The question is: Why PHP does so? What is the reason for probing strings for being numeric, and then casting if so? Why can't we just compare two strings already? I can fairly understand what casting is

How to compare a string with another where the one has space in between

怎甘沉沦 提交于 2019-12-19 07:56:13
问题 How do I compare these two string : val a = "fit bit versa" val b = "fitbit" another example val a = "go pro hero 6" val b = "gopro" another example val a = "hero go pro 6" val b = "gopro" another example val a = "hero 6 go pro" val b = "gopro" I want to get "true" for the above comparisons but not here: val a = "vegan protein powder" val b = "vega" This should be false. Currently I am doing: def matchPattern(a:String, b: String):String= { val dd = a.split(" ") val result = dd.map(_

Compare result from hexdigest() to a string

五迷三道 提交于 2019-12-19 02:54:13
问题 I've got a generated MD5-hash, which I would like to compare to another MD5-hash from a string. The statement below is false, even though they look the same when you print them and should be true. hashlib.md5("foo").hexdigest() == "acbd18db4cc2f85cedef654fccc4a4d8" Google told me that I should encode the result from hexdigest() , since it doesn't return a string. However, the code below doesn't seem to work either. hashlib.md5("foo").hexdigest().encode("utf-8") == "foo".encode("utf-8") 回答1:

is StringComparison.Ordinal the same as InvariantCulture for testing equality?

主宰稳场 提交于 2019-12-18 12:14:15
问题 From their brief summary descriptions, it sounds like the string comparison rules StringComparison.Ordinal and StringComparison.InvariantCulture are meant to differ in how they do sorting of strings. Is that all ? i.e., does that mean we can use either string comparison rule when doing an equality comparison? string.Equals(a, b, StringComparison....) And for extra credit: does it make a difference to the answer if we compare OrdinalIgnoreCase and InvariantCultureIgnoreCase ? How? Please

Why Don't We Use == To Compare Strings In Matlab

最后都变了- 提交于 2019-12-18 07:45:34
问题 I know it's commonly accepted that using strcmp is the proper way to compare strings, but my question is why? According to the help: A == B does element by element comparisons between A and B and returns a matrix of the same size with elements set to logical 1 where the relation is true and elements set to logical 0 where it is not. And all the toy examples I can come up with seem to work out. 回答1: strcmp also checks that the inputs are class char, e.g., strcmp('a',double('a')) returns false,