Questions tagged [stringcomparer]

25 questions
14
votes
4 answers

What .NET StringComparer is equivalent SQL's Latin1_General_CI_AS

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…
Stuart
  • 1,868
  • 2
  • 14
  • 14
12
votes
4 answers

Powershell Sort of Strings with Underscores

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…
bretth
  • 163
  • 8
9
votes
9 answers

Find number of characters mutual between two strings in C#

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…
Tommy
  • 445
  • 1
  • 6
  • 15
8
votes
1 answer

Linq IEqualityComparer Ignore Case

I am sorting a list of elements: var matchEle = listOfElements.Where(e => e.Properties().Any(p => p.Name.Contains("Key", Asking for IEqualityComparer))).First(); I am used to just going straight to a StringComparer, OrdinalIgnoreCase or…
AndyBernard
  • 105
  • 1
  • 9
8
votes
4 answers

Can an anonymous type inherit from another type?

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…
Dan Tao
  • 125,917
  • 54
  • 300
  • 447
6
votes
2 answers

String compare with special characters in C#

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.
6
votes
1 answer

c# SortedList.ContainsKey for successfully added key returns false

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…
Alex
  • 13,024
  • 33
  • 62
4
votes
2 answers

StringComparer.CurrentCultureIgnoreCase efficiency with multiple calls in .NET

I've been using StringComparer.CurrentCultureIgnoreCase for case-insensitive comparisons and hashing. But after checking the Reference Source I see it creates a new instance with every call (shouldn't it be a static function then? Just for form's…
user826840
  • 1,233
  • 2
  • 13
  • 28
3
votes
0 answers

Strange behaviour default string compare with underscores

Normally if a character A is smaller than character B, then I'd expect in string comparison: AB < BA And indeed, in a dictionary you can find AB words before BA words. Somehow this is not the case for underscores Small program; use copy paste to…
Harald Coppoolse
  • 28,834
  • 7
  • 67
  • 116
3
votes
2 answers

Wrong string ordering in C#

I ran this: void Main() { List strings = new List{"aaa", "z", "a"}; Console.WriteLine(string.Join("\n", strings.OrderBy(k => k))); } And the output is: a z aaa This can't be right! I was expecting a aaa z What could be the…
elnigno
  • 1,751
  • 14
  • 37
3
votes
3 answers

System.StringComparer that supports wildcard (*)

I'm looking for a fast .NET class/library that has a StringComparer that supports wildcard (*) AND incase-sensitivity. Any Ideas?
Alon Gubkin
  • 56,458
  • 54
  • 195
  • 288
2
votes
1 answer

c# weird Dictionary ContainsKey or StringComaprer

It's some kind of weird magic, ContainsKey returns false. I tried to use InvariantCulture comparer with the same result. GameCommands = new Dictionary(StringComparer.Ordinal) { {"Start new game with…
2
votes
2 answers

List C# custom sorting. Underscore after digits

I have a list: "a_a", "a1a", "aaa". I need to sort it in following way: "a1a", "a_a", "aaa". In other words I need '_' symbols to appear right after digits but before letters. I know it is possible to use custom Comparer, but I haven't found any…
zffman
  • 53
  • 5
2
votes
2 answers

Case Insensitive Array.Contains in Linq Query

I'm trying to use Array.Contains on a string array within a Linq query: var otherMatchingDevices = from d in selectedDevices from c in mldb.Companies where d.CompanyID == c.CompanyID && c.Deleted…
IanK.CO
  • 563
  • 5
  • 13
1
vote
1 answer

How do I determine type of Dictionary comparer in C#?

I need to determine whether a Dictionary I receive in a function has a case-insensitive comparer. ie. A case insensitive dictionary is declared like so: var myDict = new Dictionary(StringComparer.OrdinalIgnoreCase); When I receive…
dan
  • 5,664
  • 8
  • 45
  • 59
1
2