【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
}
相关文章
相关标签/搜索