Sobes.tech
Junior — Middle

How can a string be converted into a byte sequence?

sobes.tech AI

Answer from AI

In Go, a string (string) is a sequence of bytes in UTF-8 encoding. To convert a string to a byte sequence, simply cast it to the type []byte.

Example:

s := "Example string"
bytes := []byte(s)
fmt.Println(bytes) // Outputs a byte slice

This byte slice can be used for writing to files, transmitting over a network, and other operations with binary data.

How can a string be converted into a byte sequence… - sobes.tech