Convert between byte array/slice and string > Go 언어

본문 바로가기

Go 언어

Go 언어

4. Convert between byte array/slice and string

페이지 정보

작성자 관리자 댓글 0건 조회 4,524회 작성일 19-05-17 07:44

본문

4. Convert between byte array/slice and string

Convert string to bytes


When you convert a string to a byte slice, you get a new slice that contains the same bytes as the string.
b := []byte("ABC€")
fmt.Println(b) // [65 66 67 226 130 172]


Convert bytes to string


When you convert a slice of bytes to a string, you get a new string that contains the same bytes as the slice.

s := string([]byte{65, 66, 67, 226, 130, 172})
fmt.Println(s) // ABC€



Copyright © LEELAB.CO.KR. All rights reserved.