string.trim not working c#

Hi,

Right I've been working with vb.net for quite a few years now but have decided i need to get into c# big time so am converting a website i stated in vb over to c# to get some practice while finishing it off.

I'm having a few syntax issues so wondered if someone could have a look as based on m vb knowledge cant see whats wrong?!

I have the following vb function which works fine:
  Protected Sub btnSearch_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles btnSearch.Click
        If Not txtSearch.Text.Trim = "" And LCase(txtSearch.Text) = "search our costumes" Then
            Response.Redirect("~/FancyDressSearch/" & txtSearch.Text.Trim.Replace("  ", " ").Replace(" ", "_"))
        End If
    End Sub

I then used a convertor and got:
 protected void btnSearch_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
        if ((!txtSearch.Text.Equals("")) & (string.Compare(txtSearch.Text,"search our costumes",true) != 0))
        {
            Response.Redirect("~/FancyDressSearch/" + txtSearch.Text.Trim.Replace("  ", " ").Replace(" ", "_"));
        }
    }

I'm getting:
Error      36      'string.Trim()' is a 'method', which is not valid in the given context
....
this is on: txtSearch.Text.Trim.Replace

I cant see anything wrong with that?

Thanks in advance.
scm0smlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Try this:

If txtSearch.Text.Trim <> "" ...

Open in new window

0
käµfm³d 👽Commented:
Actually, my mistake. I thought you wanted the VB code.

A "wonderful" feature of VB is that you don't have to put parentheses on your function calls when they have no arguments. In C#, you must put parentheses. You simply need to add parentheses on the Trim calls:

protected void btnSearch_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
    if ((!txtSearch.Text.Equals("")) & (string.Compare(txtSearch.Text,"search our costumes",true) != 0))
    {
        Response.Redirect("~/FancyDressSearch/" + txtSearch.Text.Trim().Replace("  ", " ").Replace(" ", "_"));
    }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
scm0smlAuthor Commented:
yep worked this out just before i read this....

think there is going to be quite a few bits and pieces i need to get used to... case sensitive, whats that all about!!!! :)

Anyway thanks for that.
0
käµfm³d 👽Commented:
NP. Glad to help  = )
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.