I have 2 strings of the same length.
I was assuming (probably wrongly) that inserting a space between each character of each string will not change their order.
var e1 = "12*4";
var e2 = "12-4";
Console.WriteLine(String.Compare(e1,e2)); // -1 (e1 < e2)
var f1 = "1 2 * 4";
var f2 = "1 2 - 4";
Console.WriteLine(String.Compare(f1,f2)); // +1 (f1 > f2)
If you use Ordinal comparison, you will get the right result.
The reason is that ordinal comparison works by evaluating the numeric value of each of the chars in the string object, so inserting spaces will make no difference.
If you use other types of comparisons, there are other things involved. From the documentation:
An operation that uses word sort rules performs a culture-sensitive comparison wherein certain nonalphanumeric Unicode characters might have special weights assigned to them. Using word sort rules and the conventions of a specific culture, the hyphen ("-") might have a very small weight assigned to it so that "coop" and "co-op" appear next to each other in a sorted list.
An operation that uses ordinal sort rules performs a comparison based on the numeric value (Unicode code point) of each Char in the string. An ordinal comparison is fast but culture-insensitive. When you use ordinal sort rules to sort strings that start with Unicode characters (U+), the string U+xxxx comes before the string U+yyyy if the value of xxxx is numerically less than yyyy.