Skip to content

Instantly share code, notes, and snippets.

@majest
Created January 8, 2014 11:01
Show Gist options
  • Save majest/8315109 to your computer and use it in GitHub Desktop.
Save majest/8315109 to your computer and use it in GitHub Desktop.
String comparing method in golang
func StringCompare(a, b string) int {
var min = len(b)
if len(a) < len(b) {
min = len(a)
}
var diff int
for i := 0; i < min && diff == 0; i++ {
diff = int(a[i]) - int(b[i])
}
if diff == 0 {
diff = len(a) - len(b)
}
return diff
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment