strcmp(X;Y;B)
Returns an integer value that indicates the results of comparing two strings.
Syntax
strcmp(X;Y;B)
bstrcmp(X;Y;B)
Input
| Argument | Type | Description |
|---|---|---|
X |
text | The string on which to apply the function A scalar value or the name of a column |
Y |
text | The string to compare to XA scalar value or the name of a column |
B |
integer | Specifies whether the comparison is case sensitive or not If
If |
Return Value
If X<Y, this function returns an integer value of
-1.
If X>Y, it returns an integer value of
1.
If X=Y, it returns an integer value of
0.
B=0.Unicode code-point order (which does not correspond to the lexicographic order used in any particular language) is used for comparison. Generic (non-language-specific) Unicode case folding is used for case-insensitive comparisons.
If both X and Y are N/A, then the result is 0. If
X is N/A, then the result is 1. If Y is N/A, then the
result is -1.
Sample Usage
value1 |
value2 |
case sensitive |
strcmp(value;list;case sensitive) |
|---|---|---|---|
| 'banana' | 'Banana' | 0 | 0 |
| 'banana' | 'Banana' | 1 | 1 |
| 'Banana' | 'banana' | 1 | -1 |
| 'banana' | 'pear' | 1 | -1 |
| 'pear' | 'banana' | 0 | 1 |
Example
The following example shows the results of strcmp(X;Y;B) on the content of
the data in the inline table provided by the <table> operation. The
computed column results_0 displays the results of comparing the strings in
the columns string1 and string2 where the comparison is
not case sensitive (i.e., B=0). The computed column
results_1 displays the results of comparing the strings in the two
columns where the comparison is case sensitive (i.e.,
B=1).
<table cols="string1,string2"> apple,pear; Apple,apple </table> <willbe name="results_0" value="strcmp(string1;string2;0)"/> <willbe name="results_1" value="strcmp(string1;string2;1)"/>

Additional Information
strcmpis Unicode (UTF-8) compliant and will work with Unicode or plain ASCII text fields.- If passed a string argument that is not legal Unicode, it will by default signal an error (configurable as a user preference).
- A corresponding function
bstrcmpcan be used with non-Unicode strings (e.g., binary or legacy encodings).
