Order of punctuation marks vs letters

后端 未结 3 1704
孤街浪徒
孤街浪徒 2021-01-07 03:51

In C#, it is well known that \".\".CompareTo(\"A\") == -1 .

My question is: is there a punctuation mark x such that x.CompareTo(\"A\") == 1

3条回答
  •  萌比男神i
    2021-01-07 04:45

    You should simply use character with code you like (i.e. character '\uffcc' or string "\uffcc") as sentinel as long as you don't need to make it printable.

    Character comparison uses Unicode (UTF-16) character codes. So look at Unicode table to find some like:

    'A' < '{' or 'A' < '¡'.

    String comparison: there are no "<" and ">" operators in String class. You need to use Compare method. Usually you use StringComparer class to pick what type of comparison you want case sensitive, culture aware or just by Unicode values.

    Unicode type of characters impact default comparison used by CompareTo (when not using compare ordinal). Character with category "OtherLetter" is greater than character with category "OtherSymbol" or "OtherPunctuation" (Char.GetUnicodeCategory). See CompareOptions.StringSort for details.

提交回复
热议问题