Custom Search WebPart issue with apostrophe

Proposed Answer Custom Search WebPart issue with apostrophe

  • 2010年9月23日 下午 03:12
     
     

    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

所有回覆

  • 2010年9月30日 上午 08:43
     
     
    Hi, Can anyone help me on this ?
  • 2010年10月4日 下午 03:44
     
     提議的解答 包含代碼

    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
    • 已提議為解答 Mike Donahoo 2010年10月4日 下午 06:02
    •  
  • 2012年3月7日 下午 09:49
     
     
    even i have the same issue. did you got soln for it. if yes please post it