Friday, 10 May 2019

Go language: Convert string to byte array


Below statement converts string to byte array.
[]byte("Hello World

Test.go
package main

import (
 "fmt"
)

func main() {
 msg := "Hello World"

 msgBytes := []byte(msg)

 fmt.Println("msg : ", msg)
 fmt.Println("msgBytes : ", msgBytes)
}

Output
msg :  Hello World
msgBytes :  [72 101 108 108 111 32 87 111 114 108 100]



Previous                                                 Next                                                 Home

No comments:

Post a Comment