0

我尝试使用正则表达式及其工作,但在这种情况下,只有当我用大写字母输入“NVIDIA”时。我不介意在 label4 中以大写字母显示。但是,如果变量 toPring 将具有“nvidia”或“NvIdiA”,则搜索它自己不会显示正则表达式知道是否获取特定文本,如果其资本与否。

有什么方法可以让它知道以我在 toPrint 中键入的任何方式查找文本?

private void videoCardType()
        {
            string graphicsCard = string.Empty;
            foreach (ManagementObject mo in searcher.Get())
            {
                foreach (PropertyData property in mo.Properties)
                {
                    if (property.Name == "Description")
                    {
                        graphicsCard = property.Value.ToString();
                    }
                }
            }

            string toPring = "NVIDIa";
            foreach (Match m in Regex.Matches(graphicsCard, toPring, RegexOptions.IgnoreCase))
            label4.Text = toPring;
        }

问题是如果我输入 toPrint "NVIDIa" 那么 label4 中的文本将是带有小 "a" 的 "NVIDIa" 而在图形卡上方的循环中包含 "NVIDIA....gtx...."

我希望无论我在 toPrint 变量中键入什么,它都会在 label4 中显示它,因为它在 graphicsCard 变量中是原始的。

如果我在 label4 中输入 toPring“NVIDIA”或“nvidia”或“NVidiA”,根据显卡中的内容,它会像在显卡“NVIDIA”中一样。

4

2 回答 2

2

RegexOptions.IgnoreCase作为第三个参数添加到Regex.Matches.

于 2012-08-03T01:26:31.680 回答
0

您也可以用作模式:

string toPring = "(?i)NVIDIa";

玩得开心!

于 2012-08-03T02:40:48.007 回答