The strconv.Atoi()
function in Go is used to convert a string to an integer value. However, to convert a string to a byte slice, you can use the []byte
type conversion directly.
Here's an example:
package main
import (
"fmt"
)
func main() {
str := "Hello, World!"
byteSlice := []byte(str)
fmt.Printf("String: %s\n", str)
fmt.Printf("Byte Slice: %v\n", byteSlice)
}
Output:
String: Hello, World!
Byte Slice: [72 101 108 108 111 44 32 87 111 114 108 100 33]
As shown in the example, you can use []byte(str)
to convert the string str
to a byte slice.