AnyCompiler

The Standard Library

Go ships with a large, well-designed standard library, and most everyday programs barely need anything beyond it. strings has every common string operation you'd expect — ToUpper, Contains, and many more.

package main

import (
	"fmt"
	"strings"
)

func main() {
	text := "Hello, Go!"
	fmt.Println(strings.ToUpper(text))
	fmt.Println(strings.Contains(text, "Go"))
}
Output
HELLO, GO!
true

Converting between strings and numbers

strconv handles conversions between strings and numeric types. Atoi ("ASCII to integer") parses a string into an int, returning an error if the string isn't a valid number — following the same error-as-return-value pattern from earlier in this course; Itoa does the reverse.

package main

import (
	"fmt"
	"strconv"
)

func main() {
	n, err := strconv.Atoi("42")
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	fmt.Println(n + 8)

	s := strconv.Itoa(100)
	fmt.Println(s + "%")
}
Output
50
100%

That's the core of what makes Go Go: simplicity, explicit error handling, and concurrency built into the language itself. From here, the best next step is practice — pick a small idea and build it, leaning on go build to catch mistakes as you go.

Practice exercise

Using the strings package, check if "golang" contains "lang" with strings.Contains, and print the result.

← Struct EmbeddingMore lessons coming soon