locked
Help with phrase search RRS feed

  • Question

  • User1330806141 posted

    I'm creating a search function for one of my sites and I wanted to include a phrase search or exact match. The problem I'm having is, how do I capture the double quotes in the search box?

    For example: If I enter "pickup truck" in quotes. The quotes are lost when I assign the value to a string.

    dim searchString as string = textbox1.text

    Is there a way around this? If so any help would be greatly appreciated.

    Thank you,
    Jason

     

    Tuesday, March 2, 2010 11:42 AM

Answers

  • User1330806141 posted

    Wow I'm not so bright sometimes. As I was replying to the above post I thought I would include a code sample and that is when I found my answer. Before processing the request I have a vb class that I use to validate the input. I was stripping the quotes. Thank you all for your replies. I tell the other programmers all the time "the most obvious answer is almost always overlooked".

    TextBox1.Text = CommonCode.StripNonWantedCharactersFromSearchbox(TextBox1.Text)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 3, 2010 3:36 PM

All replies

  • User188494879 posted

    It should be fine. When you assign textbox.text the string you would receive should be something like this:

    \"pickup truck\"

    Try to debug your app and see the value


    Tuesday, March 2, 2010 12:38 PM
  • User1330806141 posted

    when I debug I get pickup truck as my value for searchString. By default anything typed into textbox1 is going to be wrapped in quotes when assigned to a string variable. I was expecting to see something like ""pickup truck"" since I typed quotes into the textbox. But I get "pickup truck".

     

     

    Tuesday, March 2, 2010 1:20 PM
  • User-952121411 posted

    Hummm, interesting behavior.  If I try the same code as you describe, i get ""pickup truck"" as you would like to see:

    ?MyString
    ""pickup truck""

    The code I used was nothing out of the ordinary either; just used an ASP.NET TextBox and some server side code:

    Dim MyString As String = Me.TextBox1.Text


     ..and the source:

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


    Are you by chance doing anything drastically different?  If yes, can you please post the code?

    Wednesday, March 3, 2010 11:01 AM
  • User1330806141 posted

    Wow I'm not so bright sometimes. As I was replying to the above post I thought I would include a code sample and that is when I found my answer. Before processing the request I have a vb class that I use to validate the input. I was stripping the quotes. Thank you all for your replies. I tell the other programmers all the time "the most obvious answer is almost always overlooked".

    TextBox1.Text = CommonCode.StripNonWantedCharactersFromSearchbox(TextBox1.Text)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 3, 2010 3:36 PM
  • User-952121411 posted

    StripNonWantedCharactersFromSearchbox
     

    Classic. Wink  Happens to all of us.  Glad you got it working!

    Wednesday, March 3, 2010 4:03 PM