【问题标题】:How to compare strings at C# like in SQL server case insensitive and accent insensitive [duplicate]如何在 C# 中比较字符串,如 SQL Server 不区分大小写和不区分重音 [重复]
【发布时间】:2015-03-10 10:40:29
【问题描述】:

好吧,这 4 个单词在 SQL 服务器 Latin1_General_100_CI_AI 排序规则中是相等的,不区分大小写和重音

taraflı
TaraFLI
TARaFLİ
Tarafli

但是我找不到在 C# .net 4.5.1 上将它们进行比较的方法

有没有办法像在 SQL server 中那样进行这种比较?

我也检查了这个帖子:Ignoring accented letters in string comparison

该线程的事件 RemoveDiacritics 方法失败

【问题讨论】:

  • @MelanciaUK 没有解决方案,请尝试一下
  • @MonsterMMORPG 我删除了我的答案,因为它没有帮助。
  • 不要问同样的问题。

标签: c# string-comparison case-insensitive accent-insensitive


【解决方案1】:

这会比较所有这些字符串是否相等:

string.Compare(s1,s2,
               CultureInfo.InvariantCulture,
               CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase)

【讨论】:

  • 示例 string.Compare("citroen","Citroën", CultureInfo.InvariantCulture, CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase) 0
猜你喜欢
  • 2015-03-10
  • 1970-01-01
  • 2012-02-29
  • 2014-06-20
  • 1970-01-01
  • 2013-07-22
  • 2011-06-22
  • 2018-06-08
相关资源
最近更新 更多