Order of punctuation marks vs letters

后端 未结 3 1622
孤街浪徒
孤街浪徒 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条回答
  • 2021-01-07 04:25

    Characters in C# are UTF-16 (16-bit characters).

    The following ASCII (i.e. found on a standard US keyboard) non-letter characters come after A:

    [ \ ] ^ _ `

    The following come after A as well as after lower-case a:

    ~ { | }

    There are also a number of other special characters above the ASCII range

    See

    http://www.fileformat.info/info/charset/UTF-16/list.htm

    http://en.wikipedia.org/wiki/UTF-16

    http://msdn.microsoft.com/en-us/library/dd374081.aspx

    0 讨论(0)
  • 2021-01-07 04:32

    The sort order of characters is just based on their ASCII values.

    Example ASCII table

    So yes, there are a lot of characters that are "higher" than A.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题