GO language program with example of String Compare function
String Compare function in Go language returns integer value -1, 0 or 1 after comparing two strings lexicographically. The result will be 0 if S1==S2, -1 if S1 < S2, and +1 if S1 > S2.
Example
// GO language program using String Compare function
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.Compare("India", "Indiana"))
fmt.Println(strings.Compare("Indiana", "India"))
fmt.Println(strings.Compare("India", "India"))
}
Output
-1
1
0
Most Helpful This Week
Invalid memory address or nil pointer dereference error in Golang
What is Slice Data Type in Go?
GO Program to find area and circumference of circle
Find odd and even numbers using goroutines and channels
How to delete an element from a Slice in Golang?
Example of Sscan vs Sscanf vs Sscanln from FMT Package
Golang program to print a matrix in Spiral Format
Cannot convert <type1> to <type2> error in Golang
Example to use various String Functions in Go Language
Golang Program to print Floyd's triangle