2

I need this to set the default StringComparison to StringComparison.InvariantCultureIgnoreCase.

When searching a DataTable 'ss' and 'ß' are handled as they would be the same. I don't want this behavior; I need an ordinal comparison.

DataTable table = new DataTable();
table.Locale = new CultureInfo(1031); // LCID 1031 is the default in my country (germany)
table.Columns.Add("text");

table.Rows.Add("ss");
table.Rows.Add("ß");

int rowcount = table.Select("text = 'ss'").Length; // returns: 2
Assert.AreEqual(1, rowcount); // exception

table.DefaultView.Sort = "text";
rowcount = table.DefaultView.FindRows("ß").Length; // returns: 2
Assert.AreEqual(1, rowcount); // exception

Or is there maybe a default Culture which is using OrdinalIgnoreCase? I tried LCID 7 which is the neutral german culture but this still doesn't work.

Edit 1: I guess there is no culture definied where 'ss' is not equal 'ß':

int count = CultureInfo.GetCultures(CultureTypes.AllCultures)
    .Where((item) => item.CompareInfo.Compare("ss", "ß") != 0)
    .Count(); // count = 0
Vortex852456
  • 721
  • 6
  • 23
  • 1
    Very good question. You could use `CultureInfo.InvariantCulture`, but then `ä` != `Ä`, which is probably not what you want. So you need a custom CompareInfo where `ä` = `Ä`, but `ß` != `SS`. Unfortunately, it appears that [.NET does not allow you to create a custom CompareInfo](http://stackoverflow.com/q/11138387/87698). – Heinzi Jun 27 '16 at 11:54
  • 1
    Note: *If* you manage to create a custom CompareInfo, you can use [CultureAndRegionInfoBuilder](https://msdn.microsoft.com/en-us/library/system.globalization.cultureandregioninfobuilder.cultureandregioninfobuilder(v=vs.110).aspx) to add it to a CultureInfo. – Heinzi Jun 27 '16 at 11:55

0 Answers0