CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Trim

  1. #1
    Join Date
    Sep 2009
    Posts
    3

    Trim

    Hi there
    I'm using search functionality on my website, to search for a customerid and customername.
    I'm trying to make sure the customer enters the first three characters of each of the fields.


    Could someone help me here?

    My code so far is this:


    m.merchantMID.ToLower().StartsWith(TextBox1.Text.ToLower().TrimStart()))

    &&

    m.merchantname.ToLower().StartsWith(TextBox2.Text.ToLower().TrimStart()) //


    Thanks & Regards,
    Lura

  2. #2
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: Trim

    Explain what you want to do in more detail please.

    You have a search bar on your website.
    They can search by customer ID or customer name?
    You want to make sure they enter the first 3 characters before they can search?
    Does this apply to customer ID? seems kinda weird...

    You can just check the length of the Text property in the TextBox and see if it's >= 3?

  3. #3
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Trim

    For simple check just use
    Code:
    string pattern = TextBox2.Text.ToLower().TrimStart();
    if (pattern.Lenght >= 3)
    {
      m.merchantname.ToLower().StartsWith(pattern);
    }
    For more complex testing, you'll best use regular expressions, e.g.
    Code:
    Regex m.merchantname.Match(m.merchantname, "^" + TextBox2.Text.Trim(), RegexOptions.IgnoreCase);
    Last edited by boudino; January 21st, 2010 at 05:16 AM.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  4. #4
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: Trim

    Hi boudino,

    The use of the regular expression is nice. However why do you have to conver the text to lower case even though you've specified RegexOptions.IgnoreCase?

  5. #5
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Trim

    Because of Ctrl+C, Ctrl+V

    ... I've change it now.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured