Reputation: 105
Below is the code. If I pass search value of search parameter e.g: M'test. It throws error.
What is the right way to use this code to support special character like "'"?
var graphClient = await GetGraphClient();
List<QueryOption> queryOptions = new List<QueryOption>();
queryOptions.Add(new QueryOption("$filter", string.Format("startswith(displayName,'{0}')", search)));
var collection = await graphClient.Data.Request(queryOptions).GetAsync();
Upvotes: 4
Views: 1875
Reputation: 81473
For requests that use single quotes, if any parameter values also contain single quotes, those must be double escaped; otherwise, the request will fail due to invalid syntax.
In your example, M'test
would need to be M''test
.
You could likely just use string.Replace
or regex to replace '
with ''
Upvotes: 8