locked
Custom Search WebPart issue with apostrophe RRS feed

  • Question

  • I have a custom search webpart which returns the results based on the search input from a text box. The search is performed on a managed property called "CustomerName". When the customer name has apostrophe " ' " in its text, the search results are not returned because of the wrong query formation. 

    I need to use a escape sequence and pass the search query. Can anyone help me how to form the query for this ?

    Example: Customer name : A'BCD

    Thursday, September 23, 2010 3:12 PM

All replies

  • Hi, Can anyone help me on this ?
    Thursday, September 30, 2010 8:43 AM
  • Does your custom webpart use the FullTextSqlQuery object?

    You could use a function in C# code that replaced escape characters:

    public static string ReplaceEscapeChars(string str)
    {
      //If the string is null
    
      if (str == null)
        return str;
    
      //If the string is empty
    
      if (str == "")
        return str;
    
      //Replaces single quote (') with two (2) single quotes ('') 
      //i.e.: Cox's Bazar, World's economy etc.
    
      str = str.Replace("'", "''");
      return str;
    }
    
    


    http://donahoo-development.com
    • Proposed as answer by Mike Donahoo Monday, October 4, 2010 6:02 PM
    Monday, October 4, 2010 3:44 PM
  • even i have the same issue. did you got soln for it. if yes please post it
    Wednesday, March 7, 2012 9:49 PM