|
O pacote |
|
![]()
package main |
|
import ( "fmt" s "strings" ) |
|
|
Aqui é criado um apelido para |
var p = fmt.Println |
func main() { |
|
|
Aqui está uma amostra de funções disponíveis em
|
p("Contem: ", s.Contains("test", "es"))
p("Count: ", s.Count("test", "t"))
p("TemPrefixo: ", s.HasPrefix("test", "te"))
p("TemSufixo: ", s.HasSuffix("test", "st"))
p("Índice: ", s.Index("test", "e"))
p("Join: ", s.Join([]string{"a", "b"}, "-"))
p("Repete: ", s.Repeat("a", 5))
p("Substitui: ", s.Replace("foo", "o", "0", -1))
p("Substitui: ", s.Replace("foo", "o", "0", 1))
p("Separa: ", s.Split("a-b-c-d-e", "-"))
p("letraMinuscula: ", s.ToLower("TEST"))
p("letraMaiuscula: ", s.ToUpper("test"))
}
|
$ go run string-functions.go Contem: true Count: 2 TemPrefixo: true TemSufixo: true Índice: 1 Join: a-b Repete: aaaaa Substitui: f00 Substitui: f0o Separa: [a b c d e] letraMinuscula: test letraMaiuscula: TEST |
Próximo exemplo: String Formatting.