MCPcopy Create free account
hub / github.com/mmcgrana/gobyexample / main

Function main

examples/string-functions/string-functions.go:16–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14var p = fmt.Println
15
16func main() {
17
18 // Here's a sample of the functions available in
19 // `strings`. Since these are functions from the
20 // package, not methods on the string object itself,
21 // we need to pass the string in question as the first
22 // argument to the function. You can find more
23 // functions in the [`strings`](https://pkg.go.dev/strings)
24 // package docs.
25 p("Contains: ", s.Contains("test", "es"))
26 p("Count: ", s.Count("test", "t"))
27 p("HasPrefix: ", s.HasPrefix("test", "te"))
28 p("HasSuffix: ", s.HasSuffix("test", "st"))
29 p("Index: ", s.Index("test", "e"))
30 p("Join: ", s.Join([]string{"a", "b"}, "-"))
31 p("Repeat: ", s.Repeat("a", 5))
32 p("Replace: ", s.Replace("foo", "o", "0", -1))
33 p("Replace: ", s.Replace("foo", "o", "0", 1))
34 p("Split: ", s.Split("a-b-c-d-e", "-"))
35 p("ToLower: ", s.ToLower("TEST"))
36 p("ToUpper: ", s.ToUpper("test"))
37}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected