我尝试使用Regex及其工作,但在这种情况下,只有我用大写字母键入“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;
}
问题是,如果我输入打印“NVIDIa”,那么label4中的文本将是“NVIDIa”,带有小“a”,而在上面的循环中,graphicsCard包含“NVIDIA .... gtx ....” / p>
我希望无论我在toPrint变量中输入什么,它都会在label4中显示它,因为它在graphicsCard变量中是原始的。
如果我在label4中键入toPring“NVIDIA”或“nvidia”或“NVidiA”,那么根据graphicsCard中的内容,它将类似于graphicsCard“NVIDIA”。
答案 0 :(得分:2)
将RegexOptions.IgnoreCase
作为第3个参数添加到Regex.Matches
。
答案 1 :(得分:0)
您也可以使用模式:
string toPring = "(?i)NVIDIa";
玩得开心!