Module 8 · Lesson 2 of 537/50 in the course~12 min
Module lessons (2/5)
`strings` and `strconv`
Lesson preview5 hands-on exercises readyCourse Go · Module 8 — Essential standard library
strings.Contains/Split/Join/TrimSpace, strconv.Itoa/Atoi/ParseInt/FormatFloat.
What you'll learn in this lesson
- Search, split and clean strings with
Cut,Split,Join,TrimSpaceandTrimPrefix. - Avoid quadratic allocations in loops by using
strings.Builder. - Safely convert between strings, integers, floats and booleans with
strconv. - Avoid the classic error of directly casting
string(n)to an integer.
Overview
Almost every program parses configurations, logs, or user input. In Go these tasks rely on two complementary packages: strings for searching, splitting and assembling text, and strconv for explicitly converting between string and numbers or Booleans.
Since string in Go are immutable, strings functions return new strings or slices without mutating the original:
Sections covered in this lesson
- 1Daily operations with
strings - 2Constructing text in loops with
strings.Builder - 3Safe conversions with
strconv - 4Cast trap
string(n)and string cleaning - 5Guided practice
- 6Check for understanding
Pro Lesson · Module 8 — Essential standard library
Unlock "`strings` and `strconv`" and the full Course Go curriculum
`strings.Contains/Split/Join/TrimSpace`, `strconv.Itoa/Atoi/ParseInt/FormatFloat`.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Course Go plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.