<< Click to Display Table of Contents >> Special characters considerations |
In OData queries, some characters may be unavailable for use because they might be reserved or prohibited. This affects queries with parameter values mainly; for this reason, you need to replace those special characters for their hexadecimal value to avoid further errors.
Special Characters
This is a list of some of the special characters you must replace while using them in a query with parameters.
Special Character |
( Sign ) |
Hexadecimal value |
---|---|---|
Space |
( ) |
%20 |
Backslash |
( \ ) |
%5c |
Slash |
( / ) |
%2f |
Comma |
( , ) |
%2c |
Ampersand |
( & ) |
%26 |
Dollar sign |
( $ ) |
%24 |
Percent |
( % ) |
%25 |
Equal sign |
( = ) |
%3d |
Question mark |
( ? ) |
%3f |
Hash |
( # ) |
%23 |
Quote |
( " ) |
%22 |
Single Quote |
( ' ) |
%27 |
Plus sign |
( + ) |
%252b |
Examples
Plus sign character (+)
Suppose you want to use the Plus sign ( + ) in a filter. You may want to use the following sentence.
parameters/any(p:(p/xpath eq 'My example' and contains(p/value, 'There is + 1')))
The previous sentences might not work as expected. For this reason, you have to replace the plus sign with its hexadecimal value %252b. The previous example with the new value would be:
parameters/any(p:(p/xpath eq 'My example' and contains(p/value, 'There is %252b 1')))
Quotation Marks Character (")
If the filter value contains quotation marks, then the value must be enclosed within single quotation marks; otherwise, an exception is thrown. For example:
parameters/any(p:(p/xpath eq 'String' and contains(p/value, 'take "1"')))
Single Quotation Mark Character (')
If the filter value contains a single quotation mark, then the value must be enclosed within quotation marks; otherwise, an exception is thrown. For example:
parameters/any(p:(p/xpath eq 'String' and contains(p/value, "take '1' ")))
Other cases with single and double quotation marks
If the filter contains only one quotation mark (‘“’) or only one single quotation mark (“’“), it returns all records
parameters/any(p:(p/xpath eq 'String' and contains(p/value, "'")))
If the quotation mark or single quotation mark is the last character of the string, the filter interprets it as the closing character for the value to be filtered. For example:
•If the value is: ```contains(p/value, "case'")```, then the result returns all records that contain ```case```.
•If the value is: ```contains(p/value, "case' ")```, then the result returns all records that contain ``` case' ```, (at the end of this String there is a space).
Usually, with other special characters, it is indifferent to send the character or its encoding; the filter interprets them the same way. For example:
contains(p/value, "&") and contains(p/value, "%26"), both return the same records. |
Last Updated 11/24/2023 4:38:37 PM