Virtual Chatbox in C#

Hemanth B 886 Reputation points
2021-07-09T13:46:06.82+00:00

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?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,931 questions
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2021-07-09T14:03:37.677+00:00

    Try switching this line:

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

    To:

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

1 additional answer

Sort by: Most helpful
  1. Castorix31 85,211 Reputation points
    2021-07-09T14:08:09.28+00:00

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

    See the Remarks at String.Contains with StringComparison

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.