Исходники и презентации
This commit is contained in:
17
lessons/strings/append_and_copy/main.go
Normal file
17
lessons/strings/append_and_copy/main.go
Normal file
@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
hello := []byte("Hello ")
|
||||
world := "world!"
|
||||
|
||||
helloWorld1 := append(hello, world...) // sugar
|
||||
fmt.Println(string(helloWorld1))
|
||||
|
||||
helloWorld2 := make([]byte, len(hello)+len(world))
|
||||
copy(helloWorld2, hello)
|
||||
|
||||
copy(helloWorld2[len(hello):], world) // sugar
|
||||
fmt.Println(string(helloWorld2))
|
||||
}
|
||||
Reference in New Issue
Block a user