- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
这段代码是一个简单的词汇-翻译器。我可以使用 StringComparison.CurrentCultureIgnoreCase
,以便在您输入 textBox1
时不考虑注册单词吗?
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace dс
{
public partial class Form1 : Form
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
public Form1()
{
InitializeComponent();
StreamReader sr = new StreamReader("test.txt", Encoding.UTF8);
string[] split;
while (!sr.EndOfStream)
{
split = sr.ReadLine().Split(new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries);
if (!dictionary.ContainsKey(split[0]))
{
dictionary.Add(split[0], split[1]);
}
}
sr.Close();
sr.Dispose();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Focus();
string word = textBox1.Text;
if (dictionary.ContainsKey(word))
{
textBox2.Text = dictionary[word];
}
else
{
MessageBox.Show("not found");
}
}
}
}
最佳答案
是的,您必须在字典的构造函数中指定比较器(不是 StringComparison
):
new Dictionary<string, string>(StringComparer.CurrentCultureIgnoreCase)
这将根据比较器的规则对键进行所有评估:不区分大小写。
关于c# - 字典 - StringComparison.CurrentCultureIgnoreCase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33666929/
这段代码是一个简单的词汇-翻译器。我可以使用 StringComparison.CurrentCultureIgnoreCase,以便在您输入 textBox1 时不考虑注册单词吗? using Sy
我需要支持可以在输入文本中使用非 ascii 字母的语言,因此我需要为 FirstUnmatchedIndex 实现 StringComparison.CurrentCultureIgnoreCase
在C#中做字符串比较时,和a有什么区别 string test = "testvalue"; test.Equals("TESTVALUE", StringComparison.CurrentCult
我在代码中有多个实例,我们在这些实例中完成了 StringComparison.CurrentCultureIgnoreCase 以比较两个字符串的相等性。鉴于,- 在我们的代码中,字符串基于单一文化
我一直在使用 StringComparer.CurrentCultureIgnoreCase用于不区分大小写的比较和散列。但是在检查了引用源之后,我看到它在每次调用时都会创建一个新实例(那么它不应该是
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: String comparison in dotnet framework 4 我注意到我机器上的一个 UI
我是一名优秀的程序员,十分优秀!