【Golang源碼閱讀】strings/compare.go

// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package strings

// Compare 返回按字典順序比較兩個字符串的整數。若是a == b 返回0, a < b 返回-1, a > b 返回1
// 使用內置的字符串比較運算符 ==、<、> 等一般更清晰、更快。
func Compare(a, b string) int {

	if a == b {
		return 0
	}
	if a < b {
		return -1
	}
	return +1
}
相關文章
相關標籤/搜索