我正在为学校做一个 ITP 项目。在这个项目中,我这样做是为了当我将一个单词添加到列表框中时,有一个过滤器可以在列表框中搜索该单词,如果匹配为假,则将该单词添加到列表中。但是这个过滤器不区分大小写,这意味着即使有奥迪它也会添加单词 audi,但是因为第一个字母是大写的,所以过滤器不会检测到这一点。这个位的代码是
private void btnAddWord_Click(object sender, EventArgs e)
{
if (this.lbxUnsortedList.Items.Contains(this.tbxAddWord.Text) == false)
{
//if the textbox is empty
if (tbxAddWord.Text == "")
{
MessageBox.Show("You have entered no value in the textbox.");
tbxAddWord.Focus();
}
//if the number of items in the listbox is greater than 29
if (lbxUnsortedList.Items.Count > 29)
{
MessageBox.Show("You have exceeded the maximum number of values in the list.");
tbxAddWord.Text = "";
}
//if the number of items in the listbox is less than 29
else
{
//add word to the listbox
this.lbxUnsortedList.Items.Add(this.tbxAddWord.Text);
//update tbxListBoxCount
tbxListboxCount.Text = lbxUnsortedList.Items.Count.ToString();
//onclick, conduct the bubble sort
bool swapped;
string temp;
do
{
swapped = false;
for (int i = 0; i < lbxUnsortedList.Items.Count - 1; i++)
{
int result = lbxUnsortedList.Items[i].ToString().CompareTo(lbxUnsortedList.Items[i + 1]);
if (result > 0)
{
temp = lbxUnsortedList.Items[i].ToString();
lbxUnsortedList.Items[i] = lbxUnsortedList.Items[i + 1];
lbxUnsortedList.Items[i + 1] = temp;
swapped = true;
}
}
} while (swapped == true);
tbxAddWord.Text = "";
}
}
if (this.lbxUnsortedList.Items.Contains(this.tbxAddWord.Text) == true)
{
MessageBox.Show("The word that you have added is already on the list");
tbxAddWord.Text = "";
tbxAddWord.Focus();
}
}
我想知道如何使这个大小写不敏感,这样即使第一个字母是大写,过滤器也会拾取奥迪。