Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Manipulate Strings Using the `strings` Module in Golang

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

import "strings"
strings.Index("go gopher", "go")
0
strings.Index("go gopher", "roden")
-1
strings.LastIndex("go gopher", "go")
3
strings.LastIndex("go gopher", "rodent")
-1
strings.HasPrefix("International", "Inter")
true
strings.HasSuffix("International", "national")
true
strings.Join([]string{"a", "b", "c"}, ", ")
a, b, c
strings.Replace("how are you", "how", "How", 1)
How are you
strings.ReplaceAll("how are you", "how", "How")
How are you
strings.Split("a", "a")
[ ]
strings.Split("abc", "\n")
[abc]
strings.Split("how,are,you", ",")
[how are you]