Tag: 不区分大小写

为什么我不能在C#中定义不区分大小写的字典?

这个C#/ WPF代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace TestDict28342343 { public partial class Window1 : Window { public Window1() { InitializeComponent(); Dictionary variableNamesAndValues = new Dictionary(StringComparison.InvariantCultureIgnoreCase); } } } 给我错误 : ‘System.Collections.Generic.Dictionary.Dictionary(System.Collections.Generic.IDictionary)’的最佳重载方法匹配有一些无效的参数 然而,我在这里和这里找到了这个代码示例。 如何定义其键不区分大小写的字典?

.NET如何比较两个表示文件名的字符串,正确地忽略大小写

鉴于(至少在NTFS上)Windows上的文件系统不区分大小写,我想将String fileA与String fileB进行比较: fileA.Equals(fileB, StringComparison.CurrentCultureIgnoreCase) 那么问题就变成我应该使用哪种文化,默认的当前(ui?)文化是否足够? 我似乎无法为此目的找到任何BCL方法。

使用InvariantCultureIgnoreCase而不是ToUpper进行不区分大小写的字符串比较

在这个页面上 ,一位评论者写道: 不要使用.ToUpper来确保比较字符串不区分大小写。 而不是这个: type.Name.ToUpper() == (controllerName.ToUpper() + “Controller”.ToUpper())) 做这个: type.Name.Equals(controllerName + “Controller”, StringComparison.InvariantCultureIgnoreCase) 为什么这种方式更受欢迎?

使用XPath忽略大小写的SelectNodes

我在查找XPath中包含忽略字符大小写的字符串的元素时遇到问题。 我想在HTML页面中找到所有id为id的节点都包含文本“footer”,忽略它的大写或小写。 在我的例子中,我有一个不同的html文本,如下所示: some text some text some text some text 我需要使用XPath选择所有节点(或任何情况下在id中使用“footer”一词的任何组合)。 目前我正在使用此xpath,但不适用于UpperCase id “//*[contains(./@id, ‘footer’)]/@id” 我用translate()完成了几个测试但是没有按照我的预期工作。 任何的想法? 编辑:我正在使用HtmlAgilityPack与XPath 1.0版本的工作。