question

HemanthB-9452 avatar image
0 Votes"
HemanthB-9452 asked $$ANON_USER$$ commented

Virtual Chatbox in C#

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?


dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

$$ANON_USER$$ avatar image
0 Votes"
$$ANON_USER$$ answered $$ANON_USER$$ commented

Try switching this line:

 if (label1.Text.Contains("Help"))

To:

 if (label1.Text.ToUpper().Contains("Help".ToUpper()))
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks! it works!

0 Votes 0 ·

Glad it works!

0 Votes 0 ·
Castorix31 avatar image
0 Votes"
Castorix31 answered

> It doesn't accept "help". How to make it ignore the case?

See the Remarks at String.Contains with StringComparison





5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.