Try switching this line:
if (label1.Text.Contains("Help"))
To:
if (label1.Text.ToUpper().Contains("Help".ToUpper()))
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi, I'm creating a virtual chatbox in c# which does not need any internet to function
Here's the code:
private void button1_Click(object sender, EventArgs e)
{
SendMessage();
}
private void SendMessage()
{
listBox1.Items.Add(textBox1.Text);
label1.Text = textBox1.Text;
textBox1.Text = "";
if (label1.Text.Contains("Help"))
{
listBox1.Items.Add("Here are some help topics:");
label1.Text = "";
}
else
{
listBox1.Items.Add("I'm sorry, I can't help with that");
label1.Text = "";
}
}
But this line
if (label1.Text.Contains("Help"))
{
listBox1.Items.Add("Here are some help topics:");
label1.Text = "";
}
works only if "Help" is there in the textbox. It doesn't accept "help". How to make it ignore the case?
Try switching this line:
if (label1.Text.Contains("Help"))
To:
if (label1.Text.ToUpper().Contains("Help".ToUpper()))
> It doesn't accept "help". How to make it ignore the case?
See the Remarks at String.Contains with StringComparison