How to convert a byte slice to a string in Golang?

To convert a byte slice to a string in Golang, you can use the string() function, which takes a byte slice as an argument and returns a string.

Here is an example code that demonstrates the conversion:

package main import "fmt" func main() { byteSlice := []byte{65, 66, 67, 68, 69} // Example byte slice str := string(byteSlice) // Convert byte slice to string fmt.Println(str) // Print the converted string }

Output:

ABCDE

In the example above, we have a byte slice byteSlice containing ASCII values for characters 'A' to 'E'. By using the string() function, the byte slice is converted to a string str, which is then printed to the console.