// Created on savesnippets.com · https://savesnippets.com/mz2Ih0VHd3UrrL package main import ( "fmt" "strings" ) func main() { s := " Hello, World! Hello, Go! " fmt.Println(strings.TrimSpace(s)) // "Hello, World! Hello, Go!" fmt.Println(strings.ToLower(s)) // ... lowercased fmt.Println(strings.Contains(s, "World")) // true fmt.Println(strings.HasPrefix(strings.TrimSpace(s), "Hello")) // true // Counting fmt.Println(strings.Count(s, "Hello")) // 2 // Split / Join parts := strings.Split("a,b,c,d", ",") fmt.Println(parts) // [a b c d] fmt.Println(strings.Join(parts, "|")) // a|b|c|d // Replace — N=-1 means replace all fmt.Println(strings.Replace(s, "Hello", "Hi", -1)) // Or use the dedicated ReplaceAll: fmt.Println(strings.ReplaceAll(s, "Hello", "Hi")) // Fields — split on ANY whitespace, drop empty entries fmt.Println(strings.Fields(" foo bar\tbaz\n")) // [foo bar baz] }