strings.EqualFold () в Golang с примерами

Опубликовано: 31 Января, 2022

strings.EqualFold () Функция в Golang сообщает, равны ли s и t, интерпретируемые как строки UTF-8, при свертывании регистра Unicode, которое является более общей формой нечувствительности к регистру.

Синтаксис:

func EqualFold (s1, s2 строка) bool

Здесь s1 и s2 - строки.

Возвращаемое значение: возвращает логическое значение.

Пример 1:

// Golang program to illustrate the
// strings.EqualFold() Function
package main
  
// importing fmt and strings
import (
    "fmt"
    "strings"
)
  
// calling main method
func main() {
    // case insensitive comparing and returns true.
    fmt.Println(strings.EqualFold("Geeks", "Geeks"))
  
    // case insensitive comparing and returns true.
    fmt.Println(strings.EqualFold("computerscience", "computerscience"))
}

Выход:

правда
правда

Example 2:

// Golang program to illustrate the
// strings.EqualFold() Function
package main
  
// importing fmt and strings
import (
    "fmt"
    "strings"
)
  
// calling main method
func main() {
  
    // case insensitive comparing and returns true.
    fmt.Println(strings.EqualFold("Geeks", "geeks"))
  
    // case insensitive comparing and returns true.
    fmt.Println(strings.EqualFold("COMPUTERSCIENCE", "computerscience"))
}

Выход:

правда