检查 Windows ListBox 是否包含字符串 c# ignorecase?
Check if a Windows ListBox contains a string c# ignorecase?
if (!lstFieldData.Items.Contains(ItemValue))
MessageBox.Show(ItemValue + "Item not found.");
以上代码是获取不在列表中的项目列表。
现在我想通过忽略大小写来检查这个。我怎么办?
if (strCompare.Equals("testcompare", StringComparison.InvariantCultureIgnoreCase))
{
///
}
试试这个
如果您的 lstFieldData 仅包含大写字母或小写字母,您可以使用 .ToUpper() 或 .ToLower()。
lstFieldData
A
B
C
D
if (!lstFieldData.Items.Contains(ItemValue.ToUpper()))
MessageBox.Show(ItemValue + "Item not found.");
lstFieldData
a
b
c
d
if (!lstFieldData.Items.Contains(ItemValue.ToLower()))
MessageBox.Show(ItemValue + "Item not found.");
if (!lstFieldData.Items.Contains(ItemValue))
MessageBox.Show(ItemValue + "Item not found.");
以上代码是获取不在列表中的项目列表。 现在我想通过忽略大小写来检查这个。我怎么办?
if (strCompare.Equals("testcompare", StringComparison.InvariantCultureIgnoreCase))
{
///
}
试试这个
如果您的 lstFieldData 仅包含大写字母或小写字母,您可以使用 .ToUpper() 或 .ToLower()。
lstFieldData
A
B
C
D
if (!lstFieldData.Items.Contains(ItemValue.ToUpper()))
MessageBox.Show(ItemValue + "Item not found.");
lstFieldData
a
b
c
d
if (!lstFieldData.Items.Contains(ItemValue.ToLower()))
MessageBox.Show(ItemValue + "Item not found.");