Difference between revisions of "Compare Strings (LogiX node)"
m (StringComparison type, not ComparisonType type) |
m (slight elaboration) |
||
Line 15: | Line 15: | ||
== Usage == <!--T:3--> | == Usage == <!--T:3--> | ||
− | This node | + | This node takes two strings and a <code>StringComparison</code> as input, and it outputs an integer. The <code>StringComparison</code> can be any one of the [https://docs.microsoft.com/en-us/dotnet/api/system.stringcomparer?view=net-6.0#properties StringComparer properties in C#]. It is highly recommended to avoid using the <code>CurrentCulture</code> properties as this means the string may be parsed differently depending on the locale of the user. |
<!--T:4--> | <!--T:4--> |
Latest revision as of 19:29, 11 September 2022
Compare Strings | ||
---|---|---|
Inputs | ||
String | A | |
String | B | |
StringComparison | ComparisonType | |
Outputs | ||
Int | * |
The Compare Strings node compares two strings and outputs an int depending on the value of each string.
Usage
This node takes two strings and a StringComparison
as input, and it outputs an integer. The StringComparison
can be any one of the StringComparer properties in C#. It is highly recommended to avoid using the CurrentCulture
properties as this means the string may be parsed differently depending on the locale of the user.
If you are not using an Ordinal
comparison, the node will output 1
or -1
depending on if the first string is longer or shorter than the second, respectively. If both strings are of equal length, it will compare each character in both strings and stop if two characters differ from the strings. If it stops, the node will output -1
or 1
depending on if the first string's character is of lower or higher value than the second string's character, respectively. Finally, if both strings are equal, it will output 0
If you are using an Ordinal
comparison, the node will compare each character of both strings first. If it finds a difference between the two strings, it will output the integer difference between the first two differing characters. If both strings are equal up to the end of one, but one contains more characters than the other, it will output the difference between the length of the first input and the length of the second input. Finally, if both strings are equal, it outputs 0
If you are using a comparison that has IgnoreCase
, the node will not account for case differences when comparing the two strings.