stringcomparer

c# SortedList<string, TValue>.ContainsKey for successfully added key returns false

我的未来我决定 提交于 2019-12-30 06:38:03
问题 CHECK UPDATE 3 below I found out the issue I ran into is related to a known serious problem with c# string comparers for .Net 4.0, 4.0 client and 4.5, that will lead to inconsistent sort order of lists of strings (causing the output to depend on the order in the input and the sort algorithm used). The problem was reported to Microsoft in Dec 2012 and closed as "won't be fixed". A work around is available, but is so much slower that it is hardly practical for large collections. While

c# SortedList<string, TValue>.ContainsKey for successfully added key returns false

余生长醉 提交于 2019-12-30 06:37:51
问题 CHECK UPDATE 3 below I found out the issue I ran into is related to a known serious problem with c# string comparers for .Net 4.0, 4.0 client and 4.5, that will lead to inconsistent sort order of lists of strings (causing the output to depend on the order in the input and the sort algorithm used). The problem was reported to Microsoft in Dec 2012 and closed as "won't be fixed". A work around is available, but is so much slower that it is hardly practical for large collections. While

Can an anonymous type inherit from another type?

假装没事ソ 提交于 2019-12-23 07:51:33
问题 According to the MSDN documentation on the StringComparer.OrdinalIgnoreCase property: The OrdinalIgnoreCase property actually returns an instance of an anonymous class derived from the StringComparer class. Is this a feature I'm unfamiliar with—anonymous types with inheritance? Or by "anonymous class" did the author simply mean "internal class deriving from StringComparer , not visible to client code"? 回答1: If you look at the source code for StringComparer, you can see that OrginalIgnoreCase

What .NET StringComparer is equivalent SQL's Latin1_General_CI_AS

筅森魡賤 提交于 2019-12-20 18:10:34
问题 I am implementing a caching layer between my database and my C# code. The idea is to cache the results of certain DB queries based on the parameters to the query. The database is using the default collation - either SQL_Latin1_General_CP1_CI_AS or Latin1_General_CI_AS , which I believe based on some brief googling are equivalent for equality, just different for sorting. I need a .NET StringComparer that can give me the same behavior, at least for equality testing and hashcode generation, as

Find number of characters mutual between two strings in C#

爷,独闯天下 提交于 2019-12-10 12:44:14
问题 I am looking for a method that will take two strings and return the number of characters that are common to both e.g.: "G010" & "G1820A" should return 3 as the G, 0 and 1 chars exist in both. If a char exists twice in both they should be counted separately as follows: "G12AA" & "GAA2" should return 4 as the G, A, A and 2 characters exist in both. Any help with this? Google searches haven't been too helpful thus far. 回答1: Okay, how about this, it has the advantage of maximising lazy evaluation

String compare with special characters in C#

北城余情 提交于 2019-12-07 03:10:05
问题 I have two strings " CZSczs " - " ČŽŠčžš " and I want to return true when I compare the strings. I tried with string comparison but it doesn't work. 回答1: You can use int result string.Compare("CZSczs", "ČŽŠčžš", CultureInfo.InvariantCulture, CompareOptions.IgnoreNonSpace); bool equal = result == 0; As pointed out in this question's accepted answer. 回答2: You need to specify the culture : using System; public class Program { public static void Main() { string string1 = "CZSczs"; string string2

String compare with special characters in C#

你离开我真会死。 提交于 2019-12-05 07:24:51
I have two strings " CZSczs " - " ČŽŠčžš " and I want to return true when I compare the strings. I tried with string comparison but it doesn't work. Tim Schmelter You can use int result string.Compare("CZSczs", "ČŽŠčžš", CultureInfo.InvariantCulture, CompareOptions.IgnoreNonSpace); bool equal = result == 0; As pointed out in this question 's accepted answer. You need to specify the culture : using System; public class Program { public static void Main() { string string1 = "CZSczs"; string string2 = "ČŽŠčžš"; if(String.Compare(string1, string2, CultureInfo.CurrentCulture, CompareOptions

Powershell Sort of Strings with Underscores

为君一笑 提交于 2019-12-04 00:26:20
The following list does not sort properly (IMHO): $a = @( 'ABCZ', 'ABC_', 'ABCA' ) $a | sort ABC_ ABCA ABCZ My handy ASCII chart and Unicode C0 Controls and Basic Latin chart have the underscore (low line) with an ordinal of 95 (U+005F). This is a higher number than the capital letters A-Z. Sort should have put the string ending with an underscore last. Get-Culture is en-US The next set of commands does what I expect: $a = @( 'ABCZ', 'ABC_', 'ABCA' ) [System.Collections.ArrayList] $al = $a $al.Sort( [System.StringComparer]::Ordinal ) $al ABCA ABCZ ABC_ Now I create an ANSI encoded file

System.StringComparer that supports wildcard (*)

给你一囗甜甜゛ 提交于 2019-12-01 06:37:48
问题 I'm looking for a fast .NET class/library that has a StringComparer that supports wildcard (*) AND incase-sensitivity. Any Ideas? 回答1: You could use Regex with RegexOptions.IgnoreCase, then compare with the IsMatch method. var wordRegex = new Regex( "^" + prefix + ".*" + suffix + "$", RegexOptions.IgnoreCase ); if (wordRegex.IsMatch( testWord )) { ... } This would match prefix*suffix . You might also consider using StartsWith or EndsWith as alternatives. 回答2: Alternatively you can use these