How to compare strings in Go

2 Answers

0 votes
package main
  
import (
    "fmt"
)
  
func main() {
    s1 := "Golang"
    s2 := "golang"
  
    fmt.Println(s1 == s2) 
    fmt.Println(s1 != s2) 
    fmt.Println(s1 < s2) 
    fmt.Println(s1 > s2) 
}
  
  
  
  
/*
run:
  
false
true
true
false
  
*/

 



answered May 27, 2020 by avibootz
0 votes
package main
  
import (
    "fmt"
    "strings"
)
  
func main() {
    s1 := "Golang"
    s2 := "golang"
  
    fmt.Println(strings.Compare(s1, s2)) 
    
    fmt.Println(strings.Compare("abc", "Abc")) 
    fmt.Println(strings.Compare("Abc", "abc")) 
    fmt.Println(strings.Compare("abc", "abc")) 
}
  
  
  
  
/*
run:
  
-1
1
-1
0
  
*/

 



answered May 27, 2020 by avibootz

Related questions

...