Search⌘ K

Strings, Arrays and Slices

Explore how to create manipulate and loop over strings arrays and slices in Go. Understand string immutability substring extraction byte versus character handling and fast concatenation methods. Gain practical skills to optimize your Go programs using these essential data structures.

📝 Useful code snippets for strings

Changing a character in a string

Strings are immutable, so in fact a new string is created here.

str := "hello"
c := []rune(str)
c[0] = 'c'
s2 := string(c) // s2 == "cello"

Taking a part (substring) of a string

substr := str[n:m]

Looping over a string with for or for-range

 ...