Golang strings.Compare() is an inbuilt method that returns an integer comparing two strings lexicographically. The result will be

  1. 0 if a==b
  2. -1 if a < b
  3. +1 if a > b

The Compare() function is included only for symmetry with package bytes. It is usually clearer and always faster to use the inbuilt string comparison operators ==, <, >, and so on.

How To Compare Strings in Golang

In Golang, you can compare the string using three ways.

  1. Using strings.Compare() method
  2. Using (==) operator
  3. Using strings.EqualFold() method

#go #golang

How To Compare Strings in Golang Example
1.95 GEEK