4

I am having a single quote in the data in filter condition.

Example: David O'Neil.

So If we have give this in Search Explorer as,

*&$count=true&$filter=Name eq 'David O'Neil'

How can we escape that single quote in the filter.

Update 1: If we use single quote to escape that one, 0 records are coming.

Update 2: Not able to use backslashes() also.

Arron
  • 1,134
  • 2
  • 13
  • 32

1 Answers1

10

Single quotes in OData filters are escaped by doubling:

$filter=Name eq 'David O''Neil'

Since that resulted in zero records for you, I would guess there are other issues with your data (perhaps the apostrophe in O'Neil is not the ASCII character 39 but something more ornate?)

Bruce Johnston
  • 8,344
  • 3
  • 32
  • 42
  • Doubling the single quotes does not seem to work for me. I get [AzureSearchServiceRESTCallException: {"error":{"code":"","message":"Invalid expression: Syntax error: character '\\' is not valid... It tries to escape with two back slashes in the expression. don't becomes /.*don\\'\\'t.*/ – Vivek Ayer Sep 16 '18 at 16:24
  • 1
    @VivekAyer That expression looks like a Lucene regex query, not a filter. Only the filter parameter uses the OData syntax, and the above answer is not applicable in other contexts. If you're still having trouble, please post a separate question. – Bruce Johnston Sep 17 '18 at 16:25