gobyexample/stringfuncs/stringfuncs.go

25 lines
740 B
Go
Raw Permalink Normal View History

2024-05-01 13:45:17 +00:00
package stringfuncs
import (
"fmt"
"strings"
)
var f = fmt.Println
func StringFuncs() {
f("Trim", strings.Trim("***ohaiiooo*****", "*"))
f("Split", strings.Split("a-b-c-d-e", "-"))
f("SplitAfter", strings.SplitAfter("a-b-c-d-e", "-"))
f("ToUpper", strings.ToUpper("abc"))
f("ToLower", strings.ToLower("ABC"))
f("Replace (all)", strings.Replace("foo", "o", "0", -1))
f("Replace (few)", strings.Replace("foo", "o", "0", 1))
f("Contains", strings.Contains("foobar", "bar"))
f("Count", strings.Count("fuwafuwa", "w"))
f("HasPrefix", strings.HasPrefix("foobar", "foo"))
f("HasSuffix", strings.HasSuffix("foobar", "bar"))
f("Join", strings.Join([]string{"hello", "_", "world"}, ""))
f("Index", strings.Index("foobar", "bar"))
}