Last active
December 17, 2021 23:04
-
-
Save jiaqi-yin/ae50aff587f909e83bd771de3054d995 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strconv" | |
"strings" | |
) | |
func main() { | |
// string to []byte | |
str := "hello, world" | |
b := []byte(str) | |
fmt.Printf("%T %v ~> %T %v\n", str, str, b, b) | |
// []byte to string | |
s := string(b) | |
fmt.Printf("%T %v ~> %T %v\n", b, b, s, s) | |
// number to string | |
i := 123 | |
is := strconv.Itoa(i) | |
fmt.Printf("%T %v ~> %T %v\n", i, i, is, is) | |
ii := 456 | |
iis := fmt.Sprintf("%d", ii) | |
fmt.Printf("%T %v ~> %T %v\n", ii, ii, iis, iis) | |
// string concatenation | |
strc := "abc" | |
strc = strc + "def" | |
fmt.Println(strc) | |
var sb strings.Builder | |
sb.WriteString("abc") | |
sb.WriteString("def") | |
fmt.Println(sb.String()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment