From the course: Developing Unicode-Aware Applications in Go
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
The strings package - Go Tutorial
From the course: Developing Unicode-Aware Applications in Go
The strings package
- [Instructor] Go has a strings package that helps you work with string. There's a lot of operation: cloning, comparing, cutting, getting fields, index, et cetera, et cetera. And it's really helpful, but you need to be mindful about Unicode when you work with it. Let's see an example. Say I want to parse a graph and the graph has a starts date and an ends date. So ready can go to running, running can go to either waiting or terminated, and waiting can go back to running. And I want to parse this graph and actually return a map. So I have ParseGraph, which takes a Reader and returns a map from a string, which is the source node, to a slice off all the nodes that can go there, or the destinations. So I'm starting a scanner, creating the line number, and then running over the lines. And I'm trimming the spaces for the string, and if it's an empty string, I just ignore it, otherwise I'm parsing the line. And then if everything is well, I'm appending the destination to the current source…