| 12345678910111213141516171819202122232425262728293031323334 |
- // strings.go
- package main
- import (
- "fmt"
- "strings"
- )
- func main() {
- str := "The quick brown fox jumps over the lazy dog"
- sl := strings.Fields(str)
- fmt.Printf("Splitted in slice: %v\n", sl)
- for _, val := range sl {
- fmt.Printf("%s - ", val)
- }
- fmt.Println()
- str2 := "GO1|The ABC of Go|25"
- sl2 := strings.Split(str2, "|")
- fmt.Printf("Splitted in slice: %v\n", sl2)
- for _, val := range sl2 {
- fmt.Printf("%s - ", val)
- }
- fmt.Println()
- str3 := strings.Join(sl2, ";")
- fmt.Printf("sl2 joined by ;: %s\n", str3)
- }
- /* Output:
- Splitted in slice: [The quick brown fox jumps over the lazy dog]
- The - quick - brown - fox - jumps - over - the - lazy - dog -
- Splitted in slice: [GO1 The ABC of Go 25]
- GO1 - The ABC of Go - 25 -
- sl2 joined by ;: GO1;The ABC of Go;25
- */
|