标点符号的顺序标记VS字母 [英] Order of punctuation marks vs letters

查看:141
本文介绍了标点符号的顺序标记VS字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,这是众所周知的。的CompareTo(A)== -1

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

我的问题是:有没有标点符号x满足则x.compareTo(A)== 1 (奇怪的是我无法找到答案的任何地方)

My question is: is there a punctuation mark x such that x.CompareTo("A") == 1 (strangely I can't find the answer anywhere)

或其他条款,究竟是什么在C#中的字符串完整的默认顺序?

or in other terms, what is the complete default order for strings in C# ?

我知道我可以定义Comparers和比较,但我问这个问题,因为我使用,我不能修改类和执行对字符串列表的默认字母排序。

I know I can define Comparers and Comparisons, but I am asking this question because I am using a class that I cannot modify and that performs a default alphabetical sort on a List of strings.

我的问题是,我需要把一些虚拟值在列表的末尾,我宁愿有这样的:

My problem is that I need to put some dummy values at the end of the list and I would rather have something like:

"value 1"
"value 2"
"_"
"_"
"_"

"value 1"
"value 2"
"zzz"
"zzz"
"zzz"

编辑:

这是不是很大,但我会用(char)的738

This is not great but I will use (char)738

推荐答案

您应该简单地使用字符与你喜欢的代码(即字符'\\\ᅩ 或字符串\\\ᅩ)为定点,只要你不需要使其可打印。

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.

字符比较使用Unicode(UTF-16)字符代码。所以看的Unicode表找到一些这样的:

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

'A'< '{'或'A'< 。'¡

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

字符串比较:有没有<和>运营商在String类。您需要使用比较方法。通常你使用 StringComparer 类来接你想要什么类型的比较区分大小写,文化意识到或只是Unicode值。

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的类型(如果不使用比较序号)通过的CompareTo使用的字符影响默认比较。与类别OtherLetter字比人的品格与类别OtherSymbol或OtherPunctuation(的 Char.GetUnicodeCategory )。请参见 CompareOptions .StringSort了解详情。

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.

这篇关于标点符号的顺序标记VS字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆