.NET string.Compare,String.Compare和string.CompareTo异常行为

时间:2016-11-07 22:33:42

标签: .net compare string-comparison

在回复之前请注意,我对这样的评论不感兴趣,不要这样做,使用等号或其他方法"。这里的要点是理解string.Compare和String.CompareTo的特性。从previous thread看起来比较实现了System.Globalization.CultureInfo.CurrentCulture.CompareInfo.Compare,它产生了如下所示的相同结果。

这是我的C#代码,用于各种字符串组合的Compare和CompareOrdinal结果。

(John,J):       111,     1
(John,john):    -32,     1  <<<
(John,j):       -32,     1  <<<
(J,John):      -111,    -1
(J,john):       -32,    -1
(J,j):          -32,     1  <<<
(john,John):     32,    -1  <<<
(john,J):        32,     1
(john,j):       111,     1
(j,John):        32,    -1  <<<
(j,J):           32,    -1  <<<
(j,john):      -111,    -1

虽然CompareOrdinal给出了正确的结果,但在标有&#34;&lt;&lt;&lt;&lt;&#34;的情况下,比较结果不一致with the documentation。在第一个标记结果中,Compare表示&#34; John&#34;跟随&#34; john&#34;在排序顺序中。我不知道目前的文化(US-En)是如何实现的。我在这里错过了什么吗?

       override func viewDidLoad() {
    super.viewDidLoad()
    //this will add a button to top right of the nav bar, 
    //change "ButtonName" to a title you want
    //this button will call the blackArrow function
    self.navigationItem.rightBarButtonItem = UIBarButtonItem (
        title: "ButtonName", style: UIBarButtonItemStyle.plain, target: self, action: #selector(self.blackArrow))
}


func blackArrow() {
//this function navigates to the initial view controller of the navigation controller
if let navigationController = self.navigationController {
    navigationController.popToRootViewController(animated: true)

    }
} 

0 个答案:

没有答案