小编Khw*_*smi的帖子

如何为var输入创建不区分大小写的字典 - C#

var fruitDictionary = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase) { { "Apple" , "Fruit" }, { "Orange", "Fruit" }, { "Spinach", "Greens" } };

        TextRange textRange = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd);
        string data = textRange.Text;
        var output = new StringBuilder(data);

        foreach (var kvp in fruitDictionary)
            output.Replace(kvp.Key, kvp.Value);

        var result = output.ToString();
        richTextBox2.AppendText(result);
Run Code Online (Sandbox Code Playgroud)

它正常工作,但如果输入不是格式,它将无法正常工作.例如在苹果公司,产量是水果,但在苹果上它仍然说苹果

c# dictionary case

1
推荐指数
1
解决办法
60
查看次数

标签 统计

c# ×1

case ×1

dictionary ×1