Non-Numeric Data Types
Explore the handling of non-numeric data types in Go, including strings, runes, and Unicode characters. Understand how to convert between strings and byte slices, iterate over characters, and print runes correctly using Go's built-in data types and functions.
We'll cover the following...
Go has support for strings, characters, runes, dates, and times. However, Go does not have a dedicated char data type. We begin by explaining the string-related data types.
Strings, characters, and runes
Go supports the string data type for representing strings. A Go string is just a collection of bytes and can be accessed as a whole or as an array. A single byte can store any ASCII character—however, multiple bytes are usually needed for storing a single Unicode character.
Rune data type
Nowadays, supporting Unicode characters is a common requirement—Go is designed with Unicode support in mind, which is the main reason for having the rune data type. A rune is an int32 value that is used for representing a single Unicode code ...