Search⌘ K
AI Features

The strings Package

Explore the strings package in Go to understand essential functions for text manipulation like case-insensitive comparison, substring searching, splitting, and trimming. This lesson helps you practice and master string handling techniques crucial for working with UTF-8 text in Go programming.

The strings standard Go package allows us to manipulate UTF-8 strings in Go and includes many powerful functions. Many of these functions are illustrated in the useStrings.go code file.

Note: If we are working with text and text processing, we definitely need to learn all the gory details and functions of the strings package, so let’s make sure that we experiment with all these functions and create many examples that will help us to clarify things.

Creating global aliases

The most important parts of useStrings.go are the following:

Go (1.18.2)
import (
"fmt"
s "strings"
"unicode"
)
var f = fmt.Printf

Because we are going to use the strings package multiple times, we create a convenient alias for it named s. We do the ...