Home
Blog
Most Useful Go Article
Updated
Dot Net Perls

Most Useful Go Article

For the most part, Go is a language where things are done in an obvious way. Slices, for example, are done on units of the original type, like elements in an array. But taking substrings is somewhat more complicated.

In Go, strings can be thought of as collections of bytes, and collections of characters (or runes). This is because some Unicode characters (like those with accents) have more than one byte. But ASCII strings have just one byte per character.

The Go substring article is one of my most useful:

It shows how to convert a string to a rune slice, and then when we want a substrings, we just use a slice of that.
It shows that ASCII strings can have substrings taken directly (with no rune conversion step).
It explains what to do when there is no Substring function—take slices instead.

Substrings in Go are done a little differently than in other languages like C#, but the idea of using slices for substrings makes sense. Writing the Go substring article helped me figure out this important aspect of Go.

Dot Net Perls is a collection of pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.
No updates found for this page.
Home
Changes
© 2007-2025 Sam Allen