Hi all,

I am using below code for check space but it generate errors.

my Code::

string str = TextBox1.Text;
        int l = str.Length;
        int i;
        for (i = 0; i < l; i++)
        {
            if (str[i] == " ")
            {
                Response.Write("Invalid");
            }
            else
            {
                Response.Write("valid");
            }
        }

Error::

Operator '==' cannot be applied to operands of type 'char' and 'string'

Please help me..

Thanks !

Pankaj Singh

Recommended Answers

All 4 Replies

Modify it

string str = TextBox1.Text;
int l = str.Length;
int i;http://www.egyhat.com/radio/
for (i = 0; i < l; i++)
{
if (str[i] == ' ')
{
Response.Write("Invalid");
}
else
{
Response.Write("valid");
}
}

The reason you str returns char and you assign it to " " (string) I've better solution for that if you need.

Thanks !

You're most welcome please mark it as solved.

Use IndexOf string method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.