[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

string.trim not working c#

Posted on 2011-10-27
4
Medium Priority
?
544 Views
Last Modified: 2012-08-13
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.
0
Comment
Question by:scm0sml
  • 3
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37042268
Try this:

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

Open in new window

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 37042275
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
 

Author Comment

by:scm0sml
ID: 37042331
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37042340
NP. Glad to help  = )
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question