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();
Escaping single quotes
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 ''
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With